首页 > 解决方案 > 如何订购具有 2 个字段的 Cloud Firestore 快照?

问题描述

我正在尝试订购具有 2 个字段的云 Firestore 快照。我正在使用颤振/飞镖我有这个错误:NoSuchMethodError: The getter 'lenght' was called on null。接收方:空。尝试调用:长度。另请参阅:https//flutter.dev/docs/testing/errors。

我正在使用 cloud_firestore:^2.2.0

我的代码:

  Stream<List<Friend>> getFriends() {
    return _db
        .collection('profile')
        .doc(userId)
        .collection('friends')
        .orderBy('status', descending: true)
        .orderBy('displayName', descending: false)
        .snapshots()
        .map((snapshot) => snapshot.docs
        .map((doc) => Friend.fromJason(doc.data()))
        .toList());
  }

谢谢您的帮助!

标签: firebasefluttergoogle-cloud-firestore

解决方案


在此处输入图像描述

只需添加您的索引查询。这是示例:请检查。构建索引查询需要 2-5 分钟。之后你就可以看到这样的了。

注意:如果您使用 VS Code,请转到 Debug/Terminal 您将通过单击此链接找到直接链接,索引查询将自动为您生成。链接会将您重定向到 Firestore 索引控制台


推荐阅读