带有嵌套AnimatedList的Firestore StreamBuilder [英] Firestore StreamBuilder with nested AnimatedList

查看:50
本文介绍了带有嵌套AnimatedList的Firestore StreamBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在我的应用程序的聊天方面. 并且我在StreamBuilder中设置了AnimatedList,以使消息反向显示. 这是我的代码

I am currently working on the chat aspect of my app. and I set up an AnimatedList inside of a StreamBuilder in order to make the messages appear in reverse. This is my code

      children: <Widget>[
        new Flexible(
          child: new StreamBuilder<QuerySnapshot> (
            stream: chatRoomRef.document(widget.chatRoomID).collection('messages')
                               .orderBy('time').snapshots(),
            builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
              return new AnimatedList(
                reverse: true,
                padding: const EdgeInsets.all(8.0),
                itemBuilder: (BuildContext context, int index, Animation<double> animation) {
                  return new ChatMessageListItem(
                    context: context,
                    index: index,
                    animation: animation,
                    reference: snapshot,
                  );
                }
              );
            }, 
          ),
        ),

我的问题是构建器永远不会受到影响,因此AnimatedList不会被调用.我不确定设置是否正确,因此对此表示感谢.

My problem is that the builder is never hit, so the AnimatedList is never called. I am not sure the setup is correct so any help on this is much appreciated.

我正在尝试使其像FirebaseAnimatedList小部件一样工作.我不知道这是否有助于了解我的目标.

I am trying to make it work like the FirebaseAnimatedList widget. I dont know if that helps with understanding my goal here.

谢谢

推荐答案

更新: 我通过添加自定义动画以及修改cloud_firestore文档中的代码来修复它. 我的代码现在看起来像这样

Update: I fixed it by adding a custom animation as well as modifying the code in the documentation of cloud_firestore. My code looks like this now

 new Flexible(
              child: new StreamBuilder<QuerySnapshot> (
                stream: chatRoomRef.document(widget.chatRoomID).collection('messages')
                                   .orderBy('time').snapshots(),
                builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
                  return snapshot.hasData ? new ListView(
                    physics: const AlwaysScrollableScrollPhysics(),
                    reverse: true,
                    padding: const EdgeInsets.all(8.0),
                    children: snapshot.data.documents.map((DocumentSnapshot messageSnapshot) {
                        return new ChatMessageListItem(
                        context: context,
                        animation: _animation,
                        messageSnapshot: messageSnapshot,
                        currentUserEmail: curUserEmail,
                      );
                    }).toList(),
                  ): const CircularProgressIndicator();

这篇关于带有嵌套AnimatedList的Firestore StreamBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆