简体   繁体   English

NoSuchMethodError:在 null 上调用了吸气剂“docs”。Flutter

[英]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.

相关问题 Flutter“NoSuchMethodError(NoSuchMethodError:在 null 上调用了方法‘where’。 - Flutter "NoSuchMethodError (NoSuchMethodError: The method 'where' was called on null." Error 在 null 上调用了吸气剂“imgUrl” - The getter 'imgUrl' was called on null 尝试使用 flutter 访问 Firebase 上的列表时,在 Null 错误上调用获取 getter 长度 - Getting a getter length is called on Null error when trying to access List on Firebase using flutter 在 null 上调用了方法“toDate”。 接收方:null 尝试调用:toDate() - The method 'toDate' was called on null. Receiver: null Tried calling: toDate() 获取数据错误:未处理的异常:NoSuchMethodError:在 null 上调用了方法“[]” - fetcing data error :Unhandled Exception: NoSuchMethodError: The method '[]' was called on null 在 null 上调用了方法“getString”。 接收方:null 尝试调用:getString("name") - The method 'getString' was called on null. Receiver: null Tried calling: getString("name") 未获取用户数据。 错误:在 null 上调用了吸气剂“uid” - Not Getting User Data. Error: The getter 'uid' was called on null 我该如何解决“NoSuchMethodError:在 null 上调用了方法”[]” - How can I solve "NoSuchMethodError: The method "[]" was called on null W/System(7739):忽略 header X-Firebase-Locale,因为它的值为 null。在 flutter Firebase - W/System ( 7739): Ignoring header X-Firebase-Locale because its value was null. in flutter Firebase 我正面临一个错误在 null 上调用了方法 '[]'。接收方:null 尝试调用:[]("postId") - I'm facing a error The method '[]' was called on null. Receiver: null Tried calling: []("postId")
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM