How do I create a StreamProvider that queries Firestore using data from another StreamProvider?

Viewed 394

I have a MultiProvider setup with a StreamProvider which works fine, and grabs data from a firestore query stream. I want to take this Stream A, and form another StreamProvider B which: Takes a list value from stream A, queries firestore using this list (contains-any-in query) and returns the resultant stream to the StreamProvider. Hence, for example if the list from A was to get a new element, the StreamProvider B should query firestore for data.

MultiProvider:

MultiProvider(
        providers: [
          StreamProvider<List<GroupModel>>(
              create: (context) => firestoreService.getGroups(), //StreamProvider A
          //StreamProvider B here
...

Firestore query for A:

Stream<List<GroupModel>> getGroups() {
    return _db
        .collection('groups')
        .where('users', arrayContains: _auth.currentUser!.uid)
        .snapshots()
        .map((snapshot) {
      print(snapshot.docs.toList());
      return snapshot.docs.map((e) {
        print(e.data());
        return GroupModel.fromFirestore(e.data());
      }).toList();
    });
  }
0 Answers
Related