NoSuchMethodError: The getter 'docs' was called on null. Flutter

NoSuchMethodError: The getter 'docs' was called on null. Flutter

我正在尝试开发一个 flutter 应用程序。这是一个带有一些 webview 的简单聊天应用程序。在创建所有后端和 firebase 新闻以及新用户后出现。在应用程序中,消息不会显示在聊天中。当我尝试去聊天室时出现该错误。

NoSuchMethodError (NoSuchMethodError: The getter 'docs' was called on null.

Receiver: null

Tried calling: docs)

这是我的代码

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
            });
      },
    );
  }

如果流尚未发出某些内容,则返回的快照有可能为空。使用 if 检查器检查快照是否为空。

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();

}