【问题标题】:How to display a specif document detail from firestore in flutter如何在颤动中显示来自firestore的特定文档详细信息
【发布时间】:2020-03-13 09:46:30
【问题描述】:

我正在尝试针对当前登录的用户从 firestore 获取单个文档。如果有人能提供,我需要那段代码。

【问题讨论】:

    标签: android ios flutter dart flutter-test


    【解决方案1】:

    正如cloud firestore docs 中所写,这是获取单个文档的方法:

    Firestore.instance
            .collection("users")
            .document(userId)
            .get()
            .then((DocumentSnapshot ds) {
          // use ds as a snapshot
        });
    

    如果您有用户 ID,则可以将其用作文档名称来为每个用户加载特定文档。

    【讨论】:

    • Firestore.instance.collection('Users').document("??").get().then((DocumentSnapshot ds){ print(ds); });
    • 我正在使用它,它提供了 'DocumentSnapshot' 的实例作为输出
    • 每个用户都有唯一的ID吗?您可以使用 firebase auth 来执行此操作。 pub.dev/packages/firebase_auth匿名身份验证是最容易实现的。
    • 我的集合名称“users”有 3 个名为 user-id 的文档。我如何获取特定的?我能找到那个特定文档的索引吗?
    • 尝试用用户 ID 替换 "??" 以获取他的文档
    猜你喜欢
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 2015-05-20
    相关资源
    最近更新 更多