1
votes

I have a collection of posts (/posts) each one referencing the id of the author (in /users) and I was wondering, is there a way to do a double query using a streambuilder in flutter (get the posts infos and then for each post query the users info for the authorID) ? And if not, what is the best way to approach this ? :)

Example of my firestore structure:

- posts
   - postID
      - authorID
      - text
      - timestamp
      - otherfields...

- users
   - userID
      - name
      - email
      - otherfields

1

1 Answers

2
votes

I don't think there is a way to do a firestore query without another stream. How I have solved this is with StreamZip or nested StreamBuilders.

stream: new StreamZip([stream1, stream2])

or

return StreamBuilder<FirebaseUser>(
  stream: FirebaseAuth.instance.currentUser().asStream(),
  builder: (BuildContext context, AsyncSnapshot<FirebaseUser> snapshot) {
    return StreamBuilder(
      stream: Firestore.instance.document('my_collection/$uid').snapshots(),
      builder: (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {