简体   繁体   English

如何将消息快照剥离到 flutter 中 map object 的各个字段中?

[英]How do you strip the message snapshot into the various fields of the map object in flutter?

I am not not able to get the text field in the message object in the new firestore version.在新的 Firestore 版本中,我无法获取消息 object 中的文本字段。 This doesn't work这不起作用

message.data()['text']

The code snippet I am working on我正在处理的代码片段

StreamBuilder<QuerySnapshot>(
              stream: _firestore.collection('messages').snapshots(),
              builder: (context, snapshot) {
                if (!snapshot.hasData) {
                  return Center(
                    child: CircularProgressIndicator(),
                  );
                }
                final messages = snapshot.data.docs;
                List<Text> messageWidgets = [];
                for (var message in messages) {
                  final messageText = message.data();
                  final messageWidget = Text('$messageText');
                  messageWidgets.add(messageWidget);
                }
                return Column(
                  children: messageWidgets,
                );
              },
            ),

use message.get();使用 message.get(); instead of message.data()['text']而不是 message.data()['text']

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

相关问题 Flutter:如果快照没有数据如何显示消息 - Flutter: How to show a message if snapshot has no data React Native 中如何将 or map a Firebase Snapshot child 转换为自定义 object - How to convert or map a Firebase Snapshot child into a custom object in React Native 如何使用 object snapshot.data 在简单的 flutter-dart 代码中实现空安全? - How to implement null-safety in simple flutter-dart code with object snapshot.data? 当你想要.map数据时,如何用UseState和Firebase快照定义类型? - How to define type with UseState and Firebase snapshot when you want to .map the data? 查询 flutter 中的 Firestore map 字段 - Querying Firestore map fields in flutter 如何在飞镖扑动中将对象转换为地图 - How to convert object to map in dart flutter 您如何从 PlatformException 获取消息? - How do you get the message from PlatformException? 如何在一个 flutter 应用程序中连接两个 firebase 项目? - How do you connect two firebase projects in one flutter app? Flutter:如何将快照传递给浮动操作按钮? - Flutter: How to pass snapshot to floating action button? 您如何使用 Data Snapshot 跨多个子节点检索数据? - How do you use Data Snapshot to retrieve data across multiple child nodes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM