简体   繁体   中英

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. 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(); instead of message.data()['text']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM