Nic*_*s O 3 dart firebase flutter google-cloud-firestore
在 Firestore 中,我有一个名为“习惯”的集合,每个文档都有一个包含用户 ID 的数组。我现在想获取一个包含数组中包含特定用户 ID 的所有习惯的集合。
这是我的代码:
final CollectionReference habitDataCollection = Firestore.instance.collection('habits').where("habitFollowers", arrayContains: 'userID');
Run Code Online (Sandbox Code Playgroud)
现在,我收到此错误:“查询”类型不是“CollectionReference”类型的子类型
你知道我在这里做错了什么吗?
非常感谢您的帮助!
尼古拉斯
PS:
然后代码使用 Stream 来获取快照
Stream<List<HabitData>> get habitData {
return habitDataCollection.snapshots()
.map(_habitDataListFromSnapshot);
}
Run Code Online (Sandbox Code Playgroud)
并将其形成一个飞镖对象
List<HabitData> _habitDataListFromSnapshot(QuerySnapshot snapshot) {
return snapshot.documents.map((doc){
return HabitData(
hid: doc.documentID ?? '',
name: doc.data['name'] ?? '',
description: doc.data['description'] ?? '',
);
}).toList();
}
Run Code Online (Sandbox Code Playgroud)
改变这个:
final CollectionReference habitDataCollection = Firestore.instance.collection('habits').where("habitFollowers", arrayContains: 'userID');
Run Code Online (Sandbox Code Playgroud)
进入这个:
final Query habitDataCollection = Firestore.instance.collection('habits').where("habitFollowers", arrayContains: 'userID');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2487 次 |
| 最近记录: |