Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get path of a Cloud Firestore document in Flutter

Tags:

flutter

dart

In a situation like this where I am iterating through documents inside a collection of Cloud Firestore, how can I get the path of the documents?

children: snapshot.data.documents.map((document) {
  return new ListTile(
    //want to get the document path here
    title: new Text(document.path),
  );

Apparently, you can access the path data, but the explanation I found on github was very unclear https://github.com/flutter/plugins/pull/244

like image 364
dshukertjr Avatar asked Jun 21 '18 07:06

dshukertjr


1 Answers

Taking a look at the source code:

In this line you can see that _path is a private property of DocumentSnapshot.

Also, you can see that the path is accessible in a DocumentReference, here.

This results in the following code:

children: snapshot.data.documents.map((document) {
  return new ListTile(
    title: new Text(document.reference.path), // this will return the path
);

Notice how I only added .reference.

like image 144
creativecreatorormaybenot Avatar answered Oct 03 '22 04:10

creativecreatorormaybenot