Firebase querySnapshot not updating realtime with where condition

Viewed 184

I am using cloud firestore with flutter to store the chat and using where condition to get the chats. the documents returns correctly but when the new data is added the chat list will not update in realtime.

How the chat is stored:- collection -> message {message, timestamp, sentBy,sentTo} are the message fields

the query is

firestore
        .collection('chats_v2')
        .where('sentBy', isEqualTo: 'abc')
        .where('sentTo', isEqualTo: 'xyz')
        .orderBy('timestamp')
        .snapshots();

The Chat loads perfectly for first time, but when the new message is added to collection list wont update

I also tried, this dint work:

firestore
        .collection('chats_v2')
        .where('trackId', isEqualTo: trackId)
        .where('groupId', isEqualTo: groupId)
        .orderBy('timestamp')
        .snapshots().listen((data){
          //return the QuerySnapshot from here to StreamBuilder;
        });
0 Answers
Related