首页 文章

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

提问于
浏览
1

在这样的情况下,我在云 Firestore 集合中迭代文档,如何获取文档的路径?

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

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

1 回答

  • 4

    看一下源代码:

    这条线中,您可以看到_pathDocumentSnapshot私有属性。

    此外,您可以看到path可以在DocumentReference这里中访问。

    这导致以下代码:

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

    请注意我是如何添加.reference的。

相关问题