我正在使用带有 Flutter 的 Cloud Firestore 来存储聊天并使用 where 条件来获取聊天。文档正确返回,但添加新数据时,聊天列表不会实时更新。
聊天的存储方式:- 集合 -> 消息 {message, timestamp, sentBy,sentTo} 是消息字段
查询是
firestore
.collection('chats_v2')
.where('sentBy', isEqualTo: 'abc')
.where('sentTo', isEqualTo: 'xyz')
.orderBy('timestamp')
.snapshots();
聊天第一次完美加载,但是当新消息添加到收藏列表时不会更新
我也试过了,这很有效:
firestore
.collection('chats_v2')
.where('trackId', isEqualTo: trackId)
.where('groupId', isEqualTo: groupId)
.orderBy('timestamp')
.snapshots().listen((data){
//return the QuerySnapshot from here to StreamBuilder;
});