stream - StreamBuilder InitialData 和流控制
问题描述
这是 BLoc,它有我的 BehaviorSubject 和获取流和最新流值的方法。
Stream<User> get currentUser => _currentUserSubject.stream;
User get currentUserValue => _currentUserSubject.stream.value;
final _currentUserSubject = BehaviorSubject<User>();
这是使用这些 currentUser 作为流源和 currentUserValue 作为 initialData 的 StreamBuilder:
StreamBuilder<User>(
initialData: _loginAuthBloc.currentUserValue,
stream: _loginAuthBloc.currentUser,
...)
当打开返回此 StreamBuilder 的页面时,我确保 currentUser 具有最新值。但是因为在订阅此流并返回最新值之前它有一些等待时间,所以我将 initialData 设置为 currentUserValue 以确保我们跳过该等待部分。到目前为止,一切都很好。但问题是我想忽略订阅流之后出现的值,并且在等待该流的最新值也到来之后,它与初始数据的值相同。你对此有什么建议吗?
解决方案
推荐阅读
- mongodb - MongoDB - 获取每个不同名称的最后日期
- elasticsearch - 搜索查询 [match] 格式错误的查询时出现错误,应为 [END_OBJECT] 但找到 [FIELD_NAME]
- javascript - JS 对象映射问题
- mongodb - 使用 mgo 时的更新问题
- vuejs3 - Vue3 Composition Api 检查空槽
- python - 如何通过按钮将变量传递给函数?
- artifactory - 网络界面:单击“文件的 URL:”时出现错误请求
- json - 从嵌套的 api 响应中获取 Json 数据并在表格中显示
- html - CSS - 在移动设备上 2 个 div 一个在另一个之下
- excel - 从 Excel 中的另一个单元格控制单元格值