Dart 带有嵌套AnimatedList的Firestore StreamBuilder

Dart 带有嵌套AnimatedList的Firestore StreamBuilder,dart,google-cloud-firestore,flutter,Dart,Google Cloud Firestore,Flutter,我目前正在开发我的应用程序的聊天功能。 我在StreamBuilder中设置了一个动画列表,以使消息反向显示。 这是我的密码 children: <Widget>[ new Flexible( child: new StreamBuilder<QuerySnapshot> ( stream: chatRoomRef.document(widget.chatRoomID).collection('mes

我目前正在开发我的应用程序的聊天功能。 我在StreamBuilder中设置了一个动画列表,以使消息反向显示。 这是我的密码

      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,
                  );
                }
              );
            }, 
          ),
        ),
儿童:[
新柔性(
孩子:新的StreamBuilder(
流:chatRoomRef.document(widget.chatRoomID.collection('messages'))
.orderBy('time').snapshots(),
生成器:(BuildContext上下文,异步快照){
返回新的动画列表(
相反:是的,
填充:常数边集全部(8.0),
itemBuilder:(构建上下文、int索引、动画){
返回新的ChatMessageListItem(
上下文:上下文,
索引:索引,,
动画:动画,
参考:快照,
);
}
);
}, 
),
),
我的问题是,建设者从来没有被击中,所以动画列表从来没有被调用。我不确定设置是否正确,所以在此方面的任何帮助都是非常感谢的

编辑: 我试着让它像FirebaseAnimatedList小部件一样工作。我不知道这是否有助于理解我的目标


谢谢

尝试验证快照是否有数据

            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 snapshot.hasData ? 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,
                              );
                            }
                          ): new CircularProgressIndicator();
                        }, 
                      ),
                    ),
儿童:[
新柔性(
孩子:新的StreamBuilder(
流:chatRoomRef.document(widget.chatRoomID.collection('messages'))
.orderBy('time').snapshots(),
生成器:(BuildContext上下文,异步快照){
返回snapshot.hasData?新建动画列表(
相反:是的,
填充:常数边集全部(8.0),
itemBuilder:(构建上下文、int索引、动画){
返回新的ChatMessageListItem(
上下文:上下文,
索引:索引,,
动画:动画,
参考:快照,
);
}
):新的循环压缩机指示器();
}, 
),
),
更新: 我通过添加自定义动画以及修改cloud_firestore文档中的代码来修复它。 我的代码现在看起来像这样

 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();
newflexible(
孩子:新的StreamBuilder(
流:chatRoomRef.document(widget.chatRoomID.collection('messages'))
.orderBy('time').snapshots(),
生成器:(BuildContext上下文,异步快照){
返回snapshot.hasData?新建ListView(
物理:常量AlwaysScrollablePhysics(),
相反:是的,
填充:常数边集全部(8.0),
子项:snapshot.data.documents.map((DocumentSnapshot messageSnapshot){
返回新的ChatMessageListItem(
上下文:上下文,
动画:_动画,
messageSnapshot:messageSnapshot,
currentUserEmail:curUserEmail,
);
}).toList(),
):const CircularProgressIndicator();

您在哪里声明“chatRoomRef”?我在状态类final CollectionReference chatRoomRef=Firestore.instance.collection('chatrooms')中声明它;在您的情况下,AnimatedList需要使用构造函数参数initialItemCount(它确实用于FirebaseAnimatedList:).不幸的是,这不起作用,我试图做FIrebaseAnimatedList的等价物,因为cloudstore流没有这样的功能