在 Flutter 中获取 Cloud Firestore 文档的路径

dsh*_*tjr 4 dart flutter

在这种情况下,我正在遍历 Cloud Firestore 集合中的文档,如何获取文档的路径?

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

显然,您可以访问路径数据,但是我在 github 上找到的解释非常不清楚 https://github.com/flutter/plugins/pull/244

cre*_*not 7

以一看源代码

这一行中,您可以看到这_path是 的私有财产DocumentSnapshot

此外,您可以看到path 可以DocumentReference,此处访问

这导致以下代码:

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

请注意我如何只添加 .reference.