[英]NoSuchMethodError: The getter 'docs' was called on null. Flutter
I am trying to develop a flutter app.我正在尝试开发一个 flutter 应用程序。 This is a simple chat app with some webview. After create all backend and in firebase news as well as new users show up.
这是一个简单的聊天应用程序,有一些 webview。创建所有后端后,firebase 新闻以及新用户出现。 in the app, messages won't show up in chat.
在应用程序中,消息不会显示在聊天中。 i have that error when i try to go to chat room.
当我尝试拨打 go 到聊天室时出现该错误。
NoSuchMethodError (NoSuchMethodError: The getter 'docs' was called on null.
NoSuchMethodError(NoSuchMethodError:在 null 上调用了 getter 'docs'。
Receiver: null
收件人:null
Tried calling: docs)
试过打电话:docs)
this is my code这是我的代码
class _ConversationScreenState extends State<ConversationScreen> {
DatabaseMethods databaseMethods = new DatabaseMethods();
TextEditingController messageController = new TextEditingController();
Stream chatMessageStream;
Widget ChatMessageList() {
return StreamBuilder(
stream: chatMessageStream,
builder: (
context,
snapshot,
) {
return ListView.builder(
itemCount: snapshot.data.docs.lenght, //ERROR
itemBuilder: (context, index) {
return MessageTile(snapshot.data.docs[index].data["message"]); //ERROR
});
},
);
}
There is a chance that the snapshot being returned might be null if the stream hasn't yet emitted something.如果 stream 尚未发出任何内容,则返回的快照有可能是 null。 Use an if checker to check if the snapshot is null.
使用 if 检查器检查快照是否为 null。
if(snapshot != null && snapshot.hasData){
return ListView.builder(
itemCount: snapshot.data.docs.length, //ERROR
itemBuilder: (context, index) {
return MessageTile(snapshot.data.docs[index].data["message"]); //ERROR
});
}else {
return Container();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.