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