小编Nic*_*s O的帖子

Flutter 和 Firebase:“查询”类型不是“CollectionReference”类型的子类型

在 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)

dart firebase flutter google-cloud-firestore

3
推荐指数
1
解决办法
2487
查看次数

如果在地图功能内:出现意外错误

在遵循我在网上找到的一些代码示例时,我遇到了一个意外错误。我假设我犯了一些错误,但与这里的其他示例相比,我找不到错误。我试图在 map 函数中包含一个 if 函数:

const compProfileRemoveHandler = compProfileId => {
    todoList.map(profile =>(
     if (profile.id !== compProfileId) {some code}
))};
Run Code Online (Sandbox Code Playgroud)

有谁知道我为什么会收到以下错误:“解析错误:意外的令牌”(并且在语句下标记了“if”)。

非常感谢您的帮助!

javascript arrays if-statement function reactjs

0
推荐指数
1
解决办法
86
查看次数