简体   繁体   English

Flutter Firestore QuerySnapshot 没有 getter 'document 的实例

[英]Flutter Firestore QuerySnapshot has no instance of getter 'document

I'm using this to get a list of messages from the firestore database, however, it's giving me an error:我正在使用它从 firestore 数据库获取消息列表,但是,它给了我一个错误:

flutter: The following NoSuchMethodError was thrown building: flutter: Class 'QuerySnapshot' has no instance getter 'document'. flutter: 以下 NoSuchMethodError 被抛出 building: flutter: Class 'QuerySnapshot' has no instance getter 'document'。 flutter: Receiver: Instance of 'QuerySnapshot' flutter: Tried calling: document颤振:接收器:“QuerySnapshot”实例颤振:尝试调用:文档

The code that I'm using is :我使用的代码是:

StreamBuilder(
                stream: Firestore.instance
                    .collection('messages')
                    .document(groupId)
                    .collection(groupId)
                    .orderBy('timestamp', descending: true)
                    .snapshots(),
                builder: (BuildContext context, AsyncSnapshot snapshot) {
                  if (!snapshot.hasData) {
                    return Center(
                      child: CircularProgressIndicator(),
                    );
                  } else {
                    listMessage = snapshot.data.documents;
                    return ListView.builder(
                      padding: EdgeInsets.all(10.0),
                      itemBuilder: (context, index) =>
                          buildItem(index, snapshot.data.document[index]),
                      itemCount: snapshot.data.documents.length,
                      reverse: true,
                      controller: scrollController,
                    );
                  }
                },
              ),

I'm new to Firestore and noSQL can anyone help here please?我是 Firestore 的新手,noSQL 任何人都可以帮忙吗?

我遇到了同样的问题,我的解决方法是将documents更改为docs ,请参见以下内容:

snapshot.data.docs[index]

So the problem was in the builder:(BuildContext context, AsyncSnapshot snapshot) it should have been (BuildContext context, AsyncSnapshot'<'QuerySnapshot'>' snapshot) with that added you'll be able to access snapshot.data.documents所以问题出在builder:(BuildContext context, AsyncSnapshot snapshot)它应该是(BuildContext context, AsyncSnapshot'<'QuerySnapshot'>' snapshot)加上你将能够访问snapshot.data.documents

QuerySnapshot without the quotes around the angle brackets, I had to put them there for it to show up here on Stackoverflow. QuerySnapshot没有尖括号周围的引号,我必须将它们放在那里才能显示在 Stackoverflow 上。

I had the same issue.我遇到过同样的问题。 It was a typo.这是一个错字。

snapshot.data.document[index]

should be:应该:

snapshot.data.documents[index]

I also had this problem.我也有这个问题。
My fix was to rewrite it as我的解决方法是将其重写为

snapshot.data[index]['name']
buildSearchResult() {
    return FutureBuilder(
        future: searchResultFuture,
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return circularProgress();
          }
          // otherwise if it has data
          List<Text> searchResults = [];
          snapshot.data.**documents**.forEach((doc) {
            User user = User.fromDocument(doc);
            searchResults.add(Text(user.username));
          });
          return ListView(
            children: searchResults,
          );
        });
  }

I got similar problem, mine was because I omitted the letter 's' in documents as marked bold above.我遇到了类似的问题,我的问题是因为我在文件中省略了上面标记为粗体的字母“”。 I wrote 'document' instead of 'documents'我写的是“文档”而不是“文档”

I'm using this to get a list of messages from the firestore database, however, it's giving me an error:我正在使用它来从Firestore数据库获取消息列表,但是,这给了我一个错误:

flutter: The following NoSuchMethodError was thrown building: flutter: Class 'QuerySnapshot' has no instance getter 'document'. flutter:引发了以下NoSuchMethodError构建:flutter:类'QuerySnapshot'没有实例获取方法'document'。 flutter: Receiver: Instance of 'QuerySnapshot' flutter: Tried calling: document颤动:接收者:“ QuerySnapshot”的实例颤动:尝试调用:文档

The code that I'm using is :我正在使用的代码是:

StreamBuilder(
                stream: Firestore.instance
                    .collection('messages')
                    .document(groupId)
                    .collection(groupId)
                    .orderBy('timestamp', descending: true)
                    .snapshots(),
                builder: (BuildContext context, AsyncSnapshot snapshot) {
                  if (!snapshot.hasData) {
                    return Center(
                      child: CircularProgressIndicator(),
                    );
                  } else {
                    listMessage = snapshot.data.documents;
                    return ListView.builder(
                      padding: EdgeInsets.all(10.0),
                      itemBuilder: (context, index) =>
                          buildItem(index, snapshot.data.document[index]),
                      itemCount: snapshot.data.documents.length,
                      reverse: true,
                      controller: scrollController,
                    );
                  }
                },
              ),

I'm new to Firestore and noSQL can anyone help here please?我是Firestore的新手,noSQL可以在这里帮助任何人吗?

I'm using this to get a list of messages from the firestore database, however, it's giving me an error:我正在使用它来从Firestore数据库获取消息列表,但是,这给了我一个错误:

flutter: The following NoSuchMethodError was thrown building: flutter: Class 'QuerySnapshot' has no instance getter 'document'. flutter:引发了以下NoSuchMethodError构建:flutter:类'QuerySnapshot'没有实例获取方法'document'。 flutter: Receiver: Instance of 'QuerySnapshot' flutter: Tried calling: document颤动:接收者:“ QuerySnapshot”的实例颤动:尝试调用:文档

The code that I'm using is :我正在使用的代码是:

StreamBuilder(
                stream: Firestore.instance
                    .collection('messages')
                    .document(groupId)
                    .collection(groupId)
                    .orderBy('timestamp', descending: true)
                    .snapshots(),
                builder: (BuildContext context, AsyncSnapshot snapshot) {
                  if (!snapshot.hasData) {
                    return Center(
                      child: CircularProgressIndicator(),
                    );
                  } else {
                    listMessage = snapshot.data.documents;
                    return ListView.builder(
                      padding: EdgeInsets.all(10.0),
                      itemBuilder: (context, index) =>
                          buildItem(index, snapshot.data.document[index]),
                      itemCount: snapshot.data.documents.length,
                      reverse: true,
                      controller: scrollController,
                    );
                  }
                },
              ),

I'm new to Firestore and noSQL can anyone help here please?我是Firestore的新手,noSQL可以在这里帮助任何人吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter firestore QuerySnapshot 在 Android 中没有 getter“文档”的实例 - Flutter firestore QuerySnapshot has no instance of getter 'documents' in Android 没有为 Flutter Firebase 中的“QuerySnapshot”类型错误定义吸气剂“文档” - The getter 'documents' isn't defined for the type 'QuerySnapshot' error in Flutter Firebase 颤振:文档firestore api - Flutter : document firestore api '未来<dynamic> ' 尝试访问 Flutter 中 Future SmsMessage 变量的主体时,没有实例 getter 'body' 错误</dynamic> - 'Future<dynamic>' has no instance getter 'body' error, when trying to access body of Future SmsMessage variable in Flutter 当QuerySnapshot在Firestore中的addSnapshotListener中为null时 - When QuerySnapshot will be null in addSnapshotListener in Firestore Android / FireStore QuerySnapshot转换为CustomObject - Android/FireStore QuerySnapshot convert to CustomObject NoSuchMethodError: Class '_Type' 没有实例 getter 'imgPath' - NoSuchMethodError: Class '_Type' has no instance getter 'imgPath' Cloud Firestore Flutter 无法在文档上设置数据 - Cloud firestore Flutter cannot set data on a document 在 Firestore 中检查多个文档 ID | Flutter - Check for multiple Document Id in Firestore | Flutter 如何读取文档 firestore -flutter 中的数据引用 - How to read data reference in a document firestore -flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM