Open mahi042 opened 3 years ago
This worked for me.
final messageText = message.data()['text'];
final messageSender = message.data()['sender'];
This worked for me.
final messageText = message.data()['text']; final messageSender = message.data()['sender'];
Unfortunaltely this code doesnot work for me. It says the method '[]' can't be unconditionally invoked because the receiver can be 'null' and when i add the null check sign it says the operator '[]' isn't defined for the type 'Object'.
hello all,
This is what worked for me as at Thur. 12th Aug. 2021
if (snapshot.hasData) { final messages = snapshot.data.docs; List<Text> messageWidgets = []; for (var message in messages) { final messageText = message['text']; final messageSender = message['sender']; final messageWidget = Text('$messageText from $messageSender'); messageWidgets.add(messageWidget); } return Column( children: messageWidgets, ); } else { return Text('No Data Found'); }
Nice time and God Bless.
Kind regards,
Nyanjui A.
final messageText = message['text'];
final messageSender = message['sender'];
this is what helped me
message.data() gets you the object, meanwhile message.get() gets you the object field.
final messageSender = message.get('sender');
final messageText = message.get('text');
this code bit works perfectly.
This worked for me.
final messageText = message.data()['text']; final messageSender = message.data()['sender'];
Thanks. It worked
i am getting Bad state: field does not exist within the DocumentSnapShotPlatform error message. Can someone help me?
StreamBuilder
Iam getting and error which says
The body might complete normally, causing 'null' to be returned, but the return type, 'Widget', is a potentially non-nullable type.
StreamBuilder( stream: _firestore.collection('messages').snapshots(), builder: (BuildContext context , AsyncSnapshot snapshot) { if(snapshot.hasData){ final messages = snapshot.data?.docs; List messageWidgets = []; for (var message in messages!) { final messageText = message.data()['text']; final messageSender = message.data()['sender']; final messageWidget = Text('$message from $messageSender'); messageWidgets.add(messageWidget); } return Column( children: messageWidgets, ); } }, ),
Iam getting and error which says
The body might complete normally, causing 'null' to be returned, but the return type, 'Widget', is a potentially non-nullable type.
Hey buddy!
I have the answer. You can use the below code, it worked for me.
StreamBuilder