我正在使用颤振从少数设备交换 Firestore 数据。
如果我使用 StreamBuilder 一切正常,但我不喜欢将业务逻辑与 UI 混合。我更喜欢使用 BLOC 作为使用 flutter_bloc 插件的模式。
但是 flutter_bloc 以这种方式工作:
脚步:
事件 ------------------------> 新数据但没有新的 UI 事件
异步请求
异步响应
状态(mapEventToState)-------> ¿如何获得新状态?
至于我没有“UI 事件”,因为 Firestore 数据正在从另一台设备更新,我无法更新状态。
我可以在 bloc 构造函数上使用类似的东西:
Stream<QuerySnapshot> query;
QuedadaBloc(){
query = Firestore.instance.collection('my_collection').snapshots();
query.listen((datos){
dispatch(Fetch()); // send fictitious UI event
});
}
但我认为这不是正确的方法。
¿ 有什么建议吗?
非常感谢。
J.巴勃罗。