首页 > 解决方案 > 在颤动中获取Firestore文档的documentID?

问题描述

如何在 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 的方法。

标签: dartfluttergoogle-cloud-firestore

解决方案


您正在寻找 documentId 属性。

String id = response.documentID;

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


推荐阅读