Ad

Flutter Firestore - Streambuilder Within A Streambuilder

I am trying to calculate the number of unread messages. In the first streambuilder I need to get all the document id's which match the first query.

Within that document ID I can then access the subcollection within that document and perform another query. I then need to access the result of that query.

However, within the attempt below the console outputs "past first stream" but does not enter the second streambuilder.

return StreamBuilder(
      stream: Firestore.instance
          .collection('conversations')
          .where('user_id', isEqualTo: Provider.of<User>(context).id)
          .snapshots(),
      builder: (context, snapshot) {
        if (!snapshot.hasData)
          return Center(child: CircularProgressIndicator());
        else {
          print('past first stream');
          StreamBuilder(
            stream: Firestore.instance
                .collection('conversations')
                .document('#32#0#')
                .collection('messages')
                .where('customer_message_read', isEqualTo: false)
                .snapshots(),
            builder: (context, snapshot) {
              print('im through second stream');
              if (!snapshot.hasData)
                return Center(child: CircularProgressIndicator());
              print('nope');
              QuerySnapshot querySnap = snapshot.data;
              print(querySnap.documents.length);
              return Center(child: CircularProgressIndicator());
            },
          );
          return Scaffold(
            backgroundColor: Colors.black,
            body: _children[_selectedPage],
            bottomNavigationBar: _bottomNavigationBar(context),
            resizeToAvoidBottomPadding: true,
          );
        }
      },
    );
Ad

Answer

You've created second StreamBuilder but did not return it

Ad
source: stackoverflow.com
Ad