【发布时间】:2021-07-29 18:36:10
【问题描述】:
我尝试了不同的方法,但我无法编辑代码结构
//First way
QuerySnapshot querySnapshot = await db.firestoreInstance.collection('user-history').get();
var list = querySnapshot.docs;
print('MY LIST ===== $list');
//Second way
final CollectionReference collectionRef = db.firestoreInstance
.collection(historyCollection);
print('MY SECOND LIST ===== $list');
collectionRef.get().then((qs) {
qs.docs.forEach((element) {
print('MY doc id ${element.id}');
});
});
在我的 firebase 集合(historyCollection)中,我有四个文档,但调试器返回空数组 []。还有另一种方法可以通过颤振调用某个集合中的所有文档吗? 我正在尝试通过 FutureBuilder 组件调用此方法。
我的firestore版本是:“cloud_firestore: ^0.16.0+1”
【问题讨论】:
-
当我们使用await时不必使用then,所以第一种方式去掉then,QuerySnapshot querySnapshot = await db.firestoreInstance.collection(historyCollection).get();并确保写出正确的集合名称
-
@Anna 我编辑了我的帖子并尝试这样做告诉我,但仍然没有。
-
你在这个 print('MY LIST ===== $list'); 中得到了什么??
-
尝试打印列表的长度
-
I/flutter ( 7767): MY LIST ===== [] I/flutter ( 7767): MY LIST LENGTH ===== 0 I/flutter ( 7767): MY SECOND LIST ===== [] I/flutter ( 7767): MY SECOND LIST LENGTH ===== 0
标签: flutter dart google-cloud-firestore