How to "append" firebase querysnapshots to a stream

338

I am sitting with the same problem, but I think you are on the right track. All you have to change is the for loop.

You are setting the the same QuerySnapshot to different data(personQuery).

Rather create a QuerySnapshot personQuery above the loop.

There is a way to append to a QuerySnapshot by using :

personQuery.documents.add();

Also don't use getDocuments() as this will just get the data but not the stream.

Use snapshot() instead.

Hope this helped a bit :)

Good luck coding guys.

Share:
338
GILO
Author by

GILO

cool, super duper cool. Yeahhhhhhh

Updated on December 10, 2022

Comments

  • GILO
    GILO over 1 year

    I was wondering if it is possible to "append" firebase queries onto a singular stream within flutter. Merge all the streams into a single stream.

    The code a the moment gets all the users the account follows then loops over each user id and gets their posts. I was wondering if i could merge all these queries of posts into one main stream

    Future<Stream<QuerySnapshot>> getfollowing() async{
    
        DocumentSnapshot userQuery = await Firestore.instance.collection('Users').document(id).get();//Gets who the user follows
        Stream<QuerySnapshot> fullprofilesdata ;
    
        for (String user in userQuery["following"]) {
          QuerySnapshot personQuery = await Firestore.instance.collection('Users')
              .document(user).collection("posts")
              .getDocuments();
    
    
          //fullprofilesdata.append(personQuery);
    
        }
        return fullprofilesdata;
      }