繁体   English   中英

如何仅显示包含 flutter 中的消息的聊天室

[英]How to display only those chatroom that contains messages in flutter

我正在关注创建基本聊天应用程序的频道,

在这里我想实现一件事,

以下代码显示了所有聊天室,无论是零消息还是多...

这里我不想显示那些不包含任何消息的聊天室,

就像我们清除所有消息的方式一样,聊天室不应该显示在主屏幕上,

但是在这里我不知道在哪里放置我的 where 子句以及如何计算消息数

Container(
        child: StreamBuilder(
          stream: FirebaseFirestore.instance
              .collection("chatrooms")
              .where("participants.${widget.usermodel.uid}", isEqualTo: true)
              .snapshots(),
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.active) {
              if (snapshot.hasData) {
                QuerySnapshot querysnapshot = snapshot.data as QuerySnapshot;

                return Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 10,vertical: 10),
                  child: ListView.builder(
                      itemCount: querysnapshot.docs.length,
                      itemBuilder: (context, index) {
                        ChatRoomModel chatroommodel = ChatRoomModel.fromMap(
                            querysnapshot.docs[index].data()
                                as Map<String, dynamic>);
                        Map<String, dynamic> parties =
                            chatroommodel.participants!;
                        List<String> listofpartieskey = parties.keys.toList();

                        listofpartieskey.remove(widget.usermodel.uid);
//todo futurebuilder to be studied
                        return FutureBuilder(
                            future: getuserdatabyid(listofpartieskey[0]),
                            builder: (context, userdata) {```

假设您的 chatRoomModel 有一个属性 messagesCount

chatroommodel.messageCount > 0 ? 
             FutureBuilder(...) : SizedBox.shrink()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM