【问题标题】:How can i get document from firebase store?如何从 firebase 商店获取文件?
【发布时间】:2021-01-17 11:49:07
【问题描述】:

这是我的数据。 我想要按代码记录。
那么,有什么方法可以让我在 Flutter 中获取文档?

【问题讨论】:

标签: firebase flutter dart google-cloud-firestore


【解决方案1】:

要通过代码获取文档,请使用查询:

await Firestore.instance.collection('classes')
     .where("code", isEqualTo: "9RD2699")
     .getDocuments()
     .then((event) {
       if (event.documents.isNotEmpty) {
         Map<String, dynamic> classDoc = event.documents.single.data;
       }
     }).catchError((e) => print("error fetching data: $e"));

【讨论】:

    【解决方案2】:

    你可以得到这样的文件

      Future<QuerySnapshot> getClass({String classId}) async{
        return await FirebaseFirestore.instance
            .collection('classes')
            .doc(classId)
            .get();
      }
    

    当你打电话给getClass(classId: "classId")你会得到这个类的文件

    【讨论】:

      猜你喜欢
      • 2018-09-18
      • 2020-08-18
      • 1970-01-01
      • 2018-09-08
      • 2018-11-30
      • 2022-11-25
      • 2018-09-27
      • 2013-01-22
      • 1970-01-01
      相关资源
      最近更新 更多