londonappbrewery / flash-chat-flutter

Learn to Code While Building Apps - The Complete Flutter Development Bootcamp
https://www.appbrewery.co
195 stars 677 forks source link

StreamBuilder builder error #40

Open mahi042 opened 3 years ago

mahi042 commented 3 years ago

Screenshot (6)

kevmiclee commented 3 years ago

https://stackoverflow.com/questions/64186306/closure-call-with-mismatched-arguments-function-in-flutter

This worked for me.

  final messageText = message.data()['text'];
  final messageSender = message.data()['sender'];
sulavchhetri commented 3 years ago

https://stackoverflow.com/questions/64186306/closure-call-with-mismatched-arguments-function-in-flutter

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'.

NyanjuiA commented 3 years ago

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.

fobf commented 3 years ago
 final messageText = message['text'];
final messageSender = message['sender'];

this is what helped me

syed-m-osama commented 3 years ago

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.

FireWarrior22 commented 2 years ago

https://stackoverflow.com/questions/64186306/closure-call-with-mismatched-arguments-function-in-flutter

This worked for me.

  final messageText = message.data()['text'];
  final messageSender = message.data()['sender'];

Thanks. It worked

hvb24 commented 2 years ago

i am getting Bad state: field does not exist within the DocumentSnapShotPlatform error message. Can someone help me?

rorosuperman commented 2 years ago

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.

problem
rizogiyoev commented 1 year ago

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. problem

Hey buddy!

I have the answer. You can use the below code, it worked for me.

StreamBuilder( stream: _firestore.collection('messages').snapshots(), builder: (context, snapshot) { if (snapshot.hasData) { final messages = snapshot.data!.docs; List 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 const Text('No Data Found'); } }, ),