dart - 在 flutter 中获取 Firestore 文档的 documentID?

标签 dart flutter google-cloud-firestore

Flutter 如何获取 Firestore 中文档生成的 documentID?

我知道我可以像这样访问文档的各个字段:

    return Firestore().collection(postPath).data.documents.forEach((response) {
      nodeList.add(Post(
        // response.data().id - how do i get the UID (example: -LUoDIu4wlVksjbbfIWE)?
        response['content'],
        response['date'],
        response['flair'],
        response['location'],
        response['username'],
      ));
});

但是我不确定调用获取文档的UID的方法。

最佳答案

您正在寻找 documentId 属性。

String id = response.documentID;

如果您的响应对象不存在 documentId 属性,请将 cloud_firestore 插件更新到较新的版本。

关于dart - 在 flutter 中获取 Firestore 文档的 documentID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53983045/

相关文章:

android - MissingPluginException(未找到 channel video_thumbnail 上的方法文件的实现)

dart - 如何使用 flutter 在按钮网格中滑动/拖动 2 个或更多按钮

firebase - admin.firestore(...).document 不是导出时的函数

swift - 如何使用 Firestore 合并两个查询 - Swift

api - Flutter 应用程序后端有哪些选项?

firebase - 加入两个节点的 flutter firebase_database

flutter 错误 : The following NoSuchMethodError was thrown building

firebase - 如何使用抖动流从Firestore中获取数据

flutter - Flutter-火焰与国际化?

flutter - 如何开发一个菜单,使当前路线保持在菜单的横向