【问题标题】:I set up Firestore in my project. I created new collection named most. In this collection I created 10 documents. but my code is getting error我在我的项目中设置了 Firestore。我创建了名为 most 的新集合。在这个集合中,我创建了 10 个文档。但我的代码出错了
【发布时间】:2022-01-14 06:45:12
【问题描述】:

我在我的项目中设置了 Firestore。我创建了名为 most 的新集合。在这个集合中,我创建了 10 个文档。但我的代码出错了!

Future getMost() async {
      final firestore = FirebaseFirestore.instance;
      QuerySnapshot snapshot =
          await firestore.collection('most').getDocuments();
      return snapshot.documents;
    }

getDocuments 出现错误...还有其他方法吗

【问题讨论】:

标签: flutter dart google-cloud-firestore


【解决方案1】:
  1. 首先,检查您是否在项目中正确设置了 Firestore: 结帐this指导安装部分
  1. 在您的项目中正确设置 Firestore 后,使用最新的方法,get(),而不是您的收藏参考中的 getDocuments()
Future getMost() async {
      final firestore = FirebaseFirestore.instance;
      QuerySnapshot snapshot =
          await firestore.collection('most').get();
      return snapshot.docs;
    }

【讨论】:

    猜你喜欢
    • 2021-10-20
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    • 2020-06-23
    • 2019-11-30
    • 2018-05-07
    • 1970-01-01
    • 2022-10-13
    相关资源
    最近更新 更多