【问题标题】:How can i retrieve a field value from a specific document in firestore using flutter?如何使用颤振从 Firestore 中的特定文档中检索字段值?
【发布时间】:2021-08-11 13:07:37
【问题描述】:

这是我编写的代码,但遇到了一些错误,例如“无法在 getOptions() 中使用字符串”

                totalClasses = await FirebaseFirestore.instance
                    .collection('tutors')
                    .doc(uid)
                    .get("TotalClassesTook")
                    .then((value) {
                  return value.data();
                });

How to retrieve the TotalClassesTook field value from this doc Error image

【问题讨论】:

  • 您在代码中的哪个位置使用getOptions
  • @NisanthReddy,现在我附上了错误图片,请检查一次。

标签: android firebase flutter dart google-cloud-firestore


【解决方案1】:

在使用FirebaseFirestore.instance 获取数据时,.get() 用于指定具有cache 等功能的GetOptions

但这不是你需要的。

这样使用,

totalClasses = await FirebaseFirestore.instance
    .collection('tutors')
    .doc(uid)
    .get()
    .then((value) {
       return value.data()['TotalClassesTook']; // Access your after your get the data
     });

【讨论】:

    猜你喜欢
    • 2020-08-05
    • 2021-08-11
    • 2021-04-14
    • 2019-01-09
    • 1970-01-01
    • 2021-08-10
    • 2023-01-29
    • 2021-09-23
    相关资源
    最近更新 更多