Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 颤振联系人列表显示顺序_Firebase_Flutter_Google Cloud Firestore - Fatal编程技术网

Firebase 颤振联系人列表显示顺序

Firebase 颤振联系人列表显示顺序,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我创建了一个与长笛聊天应用程序,目前我有一个问题的聊天列表联系人显示,我的联系人列表显示,但不是在我希望它的顺序 我想要的是显示用户未读的消息联系人到列表的顶部,因此每次用户发送消息时,用户都会跳到接收者列表的顶部 Stream<QuerySnapshot> fetchContacts({String userId}) => _userCollection .document(userId) .collection(CONTACTS_COLLECTION) .s

我创建了一个与长笛聊天应用程序,目前我有一个问题的聊天列表联系人显示,我的联系人列表显示,但不是在我希望它的顺序

我想要的是显示用户未读的消息联系人到列表的顶部,因此每次用户发送消息时,用户都会跳到接收者列表的顶部

  Stream<QuerySnapshot> fetchContacts({String userId}) => _userCollection
  .document(userId)
  .collection(CONTACTS_COLLECTION)
  .snapshots();
Stream fetchContacts({String userId})=>\u userCollection
.document(userId)
.collection(CONTACTS_collection)
.快照();
联系人列表代码

Container(
  child: StreamBuilder<QuerySnapshot>(
      stream: _chatMethods.fetchContacts(
        userId: userProvider.getUser.uid,
      ),
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          var docList = snapshot.data.documents;

          if (docList.isEmpty) {
            return QuietBox(
              heading: "This is where all the contacts are listed",
              subtitle: "You can now start calling or chatting with Tinus",
            );
          }
          return ListView.builder(
            padding: EdgeInsets.all(10),
            itemCount: docList.length,
            itemBuilder: (context, index) {
              Contact contact = Contact.fromMap(docList[index].data);

              return ContactView(contact);
            },
          );
        }

        return Center(child: CircularProgressIndicator());
      }),
)
容器(
孩子:StreamBuilder(
流:\ u chatMethods.fetchContacts(
userId:userProvider.getUser.uid,
),
生成器:(上下文,快照){
if(snapshot.hasData){
var docList=snapshot.data.documents;
如果(docList.isEmpty){
返回静音盒(
标题:“这是列出所有联系人的地方”,
副标题:“您现在可以开始与Tinus通话或聊天了”,
);
}
返回ListView.builder(
填充:边缘设置。全部(10),
itemCount:docList.length,
itemBuilder:(上下文,索引){
Contact Contact=Contact.fromMap(docList[index].data);
返回ContactView(联系人);
},
);
}
返回中心(子项:CircularProgressIndicator());
}),
)
联系卡

   return StreamBuilder(
  builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
    return StreamBuilder<QuerySnapshot>(
        stream: Firestore.instance
            .collection('users')
            .document(contact.uid)
            .collection('chatlist')
            .where('chatWith', isEqualTo: userProvider.getUser.uid)
            .snapshots(),
        builder: (context, chatListSnapshot) {
          return CustomTile(
            mini: false,
            onTap: () => Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => ChatScreen(
                    receiver: contact,
                  ),
                )),
            title: Text(
              (contact != null ? contact.name : null) != null
                  ? contact.name
                  : "..",
              style: TextStyle(
                  color: Colors.white, fontFamily: "Arial", fontSize: 19),
            ),
            subtitle: LastMessageContainer(
              stream: _chatMethods.fetchLastMessageBetween(
                senderId: userProvider.getUser.uid,
                receiverId: contact.uid,
              ),
            ),
            leading: Container(
              constraints: BoxConstraints(maxHeight: 60, maxWidth: 60),
              child: Stack(
                children: <Widget>[
                  CachedImage(
                    contact.profilePhoto,
                    radius: 80,
                    isRound: true,
                  ),
                  OnlineDotIndicator(
                    uid: contact.uid,
                  ),
                ],
              ),
            ),
            trailing: Padding(
                padding: const EdgeInsets.fromLTRB(0, 8, 4, 4),
                child: (chatListSnapshot.hasData &&
                        chatListSnapshot.data.documents.length > 0)
                    ? StreamBuilder<QuerySnapshot>(
                        stream: Firestore.instance
                            .collection('messages')
                            .document(userProvider.getUser.uid)
                            .collection(contact.uid)
                            .where('receiverId',
                                isEqualTo: userProvider.getUser.uid)
                            .where('isread', isEqualTo: false)
                            .snapshots(),
                        builder: (context, notReadMSGSnapshot) {
                          return Container(
                            width: 60,
                            height: 50,
                            child: Column(
                              children: <Widget>[
                                Text(
                                  (chatListSnapshot.hasData &&
                                          chatListSnapshot
                                                  .data.documents.length >
                                              0)
                                      ? readTimestamp(chatListSnapshot
                                          .data.documents[0]['timestamp'])
                                      : '',
                                  style: TextStyle(
                                      fontSize: 12, color: Colors.white),
                                ),
                                Padding(
                                    padding: const EdgeInsets.fromLTRB(
                                        0, 5, 0, 0),
                                    child: CircleAvatar(
                                      radius: 9,
                                      child: Text(
                                        (chatListSnapshot.hasData &&
                                                chatListSnapshot.data
                                                        .documents.length >
                                                    0)
                                            ? ((notReadMSGSnapshot
                                                        .hasData &&
                                                    notReadMSGSnapshot
                                                            .data
                                                            .documents
                                                            .length >
                                                        0)
                                                ? '${notReadMSGSnapshot.data.documents.length}'
                                                : '')
                                            : '',
                                        style: TextStyle(fontSize: 10),
                                      ),
                                      backgroundColor: (notReadMSGSnapshot
                                                  .hasData &&
                                              notReadMSGSnapshot.data
                                                      .documents.length >
                                                  0 &&
                                              notReadMSGSnapshot.hasData &&
                                              notReadMSGSnapshot.data
                                                      .documents.length >
                                                  0)
                                          ? Colors.red[400]
                                          : Colors.transparent,
                                      foregroundColor: Colors.white,
                                    )),
                              ],
                            ),
                          );
                        })
                    : Text('')),
          );
        });
  },
);
返回StreamBuilder(
生成器:(上下文,异步快照){
返回流生成器(
流:Firestore.instance
.collection('用户')
.document(contact.uid)
.collection('chatlist')
.where('chatWith',isEqualTo:userProvider.getUser.uid)
.snapshots(),
生成器:(上下文,chatListSnapshot){
返回自定义磁砖(
米尼:错,
onTap:()=>Navigator.push(
上下文
材料路线(
生成器:(上下文)=>ChatScreen(
接收人:联系人:,
),
)),
标题:正文(
(contact!=null?contact.name:null)!=null
?联系人姓名
: "..",
样式:TextStyle(
颜色:Colors.white,字体系列:“Arial”,字体大小:19),
),
字幕:LastMessageContainer(
流:_chatMethods.fetchLastMessageBetween(
senderId:userProvider.getUser.uid,
收款人:contact.uid,
),
),
领先:集装箱(
约束:框约束(最大高度:60,最大宽度:60),
子:堆栈(
儿童:[
恶病质图像(
联系人:profilePhoto,
半径:80,
是的,
),
在线指示器(
uid:contact.uid,
),
],
),
),
尾随:填充(
填充:从LTRB(0,8,4,4)开始的常数边集,
子项:(chatListSnapshot.hasData)&&
chatListSnapshot.data.documents.length>0)
?StreamBuilder(
流:Firestore.instance
.collection('消息')
.document(userProvider.getUser.uid)
.collection(contact.uid)
.其中(‘接收方’,
isEqualTo:userProvider.getUser.uid)
.where('isread',isqualto:false)
.snapshots(),
生成器:(上下文,notReadMSGSnapshot){
返回容器(
宽度:60,
身高:50,
子:列(
儿童:[
正文(
(chatListSnapshot.hasData)&&
聊天列表快照
.data.documents.length>
0)
?读取时间戳(chatListSnapshot)
.data.documents[0]['timestamp'])
: '',
样式:TextStyle(
字体大小:12,颜色:颜色。白色),
),
填充物(
填充:const EdgeInsets.fromLTRB(
0, 5, 0, 0),
孩子:圆环星(
半径:9,
子:文本(
(chatListSnapshot.hasData)&&
chatListSnapshot.data
.documents.length>
0)
?((不读取msgsnapshot)
.hasData&&
notReadMSGSnapshot
.数据
.文件
.长度>
0)
?“${notReadMSGSnapshot.data.documents.length}”
: '')
: '',