Flutter Firestore - streambuilder 中的 Streambuilder

Flutter Firestore - Streambuilder within a streambuilder

我正在计算未读消息的数量。在第一个 streambuilder 中,我需要获取所有与第一个查询匹配的文档 ID。

在该文档 ID 中,我可以访问该文档中的子集合并执行另一个查询。然后我需要访问该查询的结果。

然而,在下面的尝试中,控制台输出 "past first stream" 但没有进入第二个 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,
          );
        }
      },
    );

您创建了第二个 StreamBuilder 但没有 return