可以从 Firestore 快照 Flutter 获取元数据吗?

Flu*_*ase 5 dart firebase google-cloud-platform flutter google-cloud-firestore

我需要获取snapshot元数据,以便检查写入 Firestore 是否成功。我查看源代码 ,发现有SnapshotMetadata和 boolean hasPendingWrites()。但我找不到如何实施。没有开源 dart 项目使用过它。

Firebase文档说可以使用:.onSnapshot/.addSnapshotListener来指定includeMetadataChanges: true

但我需要确保在查询QuerySnapshot. 我用的query不是。streamaddSnapshotListener

像这样:

        child: new FirestoreAnimatedList(
          query: Firestore.instance.collection('Collection')
              .orderBy('timestamp', descending: true)
              .snapshots(),
          padding: new EdgeInsets.all(8.0),
          reverse: true,
          itemBuilder: (_, DocumentSnapshot snapshot,
              Animation<double> animation, int x) {
            return new Chat(
                snapshot: snapshot, animation: animation);
          },
        ),
Run Code Online (Sandbox Code Playgroud)

我尝试指定:

          query: Firestore.instance.collection('Collection')
              .snapshots(includeMetadataChanges: true),
Run Code Online (Sandbox Code Playgroud)

但这是不可能的:

错误:未定义命名参数“includeMetadataChanges”。

我也尝试:

snapshot.getMetadata().hasPendingWrites()
Run Code Online (Sandbox Code Playgroud)

但给出错误:

错误:未为类“DocumentSnapshot”定义方法“getMetaData”。

有谁知道在 Flutter 中如何做到这一点?有可能吗?

我尝试了很长时间但找不到如何..帮助!

谢谢!

Fra*_*len 0

看起来DocumentSnapshotFlutterFire 中的类没有公开底层文档的元数据。我会在Flutter repo上提交一个功能请求。