dart - 在颤动中获取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 的方法。
解决方案
您正在寻找 documentId 属性。
String id = response.documentID;
如果您的响应对象不存在 documentId 属性,请将 cloud_firestore 插件更新为较新的版本。
推荐阅读
- java - 将未知类型(对象或原始)数组的引用传递给函数
- python - 在多个列表中查找共同值
- c++ - 以结构为参数的函数产生错误:free():无效指针:0x00007efd47b
- sql - 在窗口函数旁边使用常规聚合函数(sum)
- c# - Update-Database 命令在建立与服务器的连接时出错(代码优先迁移)
- angular - Angular 提前编译问题
- prolog - 在 Prolog 中,如何将查询的所有答案转换为列表?
- objective-c - 如何在情节提要中平移视图控制器
- r - Tikzpictures 不在 gitbook 中呈现,即使它们出现在 pdf_book 中
- asp.net-mvc - 使用 Cybersource .Net 客户端库执行事务搜索时出现 NLOG 错误