gpt4 book ai didi

firebase - Firestore:在控制台中显示收集文档

转载 作者:行者123 更新时间:2023-12-03 04:42:22 24 4
gpt4 key购买 nike

我有一个使用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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com