我有一个使用Firestore数据库的Flutter应用程序,我想在控制台中显示“产品”集合中的数据,但是我收到的是:
I/flutter ( 5747): Instance of 'Future<QuerySnapshot>'
有没有一种方法可以实现..这是我的代码:Future<void> getItems() async {
final response = await Firestore.instance.collection("products").getDocuments();
print(json.decode(json.decode(response)));
}
最佳答案
这应该工作:
Future<void> getItems() async {
final response = await Firestore.instance.collection("products").getDocuments();
response.documents.forEach((element) {
print(element.data);
});
}
由于您使用的是await
,因此getDocuments()
应该返回QuerySnapshot
,然后可以使用documents
进行迭代。
关于firebase - Firestore:在控制台中显示收集文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62979385/