Carrein
Carrein

Reputation: 3371

Getting the documentID of a Firestore document in flutter?

How do I get the generated documentID of a document in Firestore in Flutter?

I know I can access the various fields of a document like this:

    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'],
      ));
});

But I am unsure of the method to call get the UID of the document.

Upvotes: 1

Views: 3754

Answers (1)

dshukertjr
dshukertjr

Reputation: 18730

You are looking for documentId property.

String id = response.documentID;

If documentId property does not exist for your response object, update the cloud_firestore plugin to a newer version.

Upvotes: 5

Related Questions