简体   繁体   English

如何从 flutter 中的 firebase 访问文档 ID?

[英]How to access document ID from firebase in flutter?

I am working with flutter and firebase.我正在使用 flutter 和 firebase。 I have a collection with a list of documents, and those documents further have many fields each.我有一个包含文档列表的集合,这些文档每个都有很多字段。 I have an API for accessing the documents, which returns a list of the details in each document.我有一个 API 用于访问文档,它返回每个文档中的详细信息列表。 But, I want to access the document id of each document.但是,我想访问每个文档的文档 ID。 How to do that?怎么做?

If you write such a query you can have every documentId of your documents.如果您编写这样的查询,您可以获得文档的每个 documentId。

_getDocuments() async {
await _firestore.collection("yourCollection").getDocuments().
then((myDocuments) {
  for (DocumentSnapshot eachDocument in myDocuments.documents) {
       print(eachDocument.documentID);
    } 
  }
});

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM