dart - 带有嵌套 AnimatedList 的 Firestore StreamBuilder

标签 dart google-cloud-firestore flutter

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

      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。我不确定设置是否正确,因此非常感谢任何帮助。

编辑: 我试图让它像 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();
                        }, 
                      ),
                    ),

关于dart - 带有嵌套 AnimatedList 的 Firestore StreamBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51681823/

相关文章:

flutter - 将 Flutter 应用程序屏幕导出为 PDF

flutter - Flutter 中的持久代码

java - 如何更新文档内的 arrayList?

mobile - 是否可以在 Linux 虚拟机上使用 Flutter 开发 iOS 应用程序?

flutter - 如果我在 Debug模式下运行我的应用程序,如何关闭 Firebase 分析/crashlytics?

xcode - 您的 Xcode 版本对于您的 iOS 版本来说可能太旧了

firebase - 卡住的 Json 序列化程序 - firestore 通信

firebase - 如何通过 Flutter 在 Firestore 中添加 Geopoint、时间戳和对文档的引用

Flutter 的 Firebase 读/写规则不起作用?

testing - 在 VSCODE 上运行所有测试时出现 Flutter SIGINT 错误