【发布时间】:2019-07-28 00:43:24
【问题描述】:
我需要获取snapshot 元数据,以便检查写入 Firestore 是否成功。我查看source,发现有SnapshotMetadata 和布尔值hasPendingWrites()。但我找不到如何实施。没有开源 dart 项目使用过它。
Firebase doc 说可以使用:.onSnapshot / .addSnapshotListener 指定includeMetadataChanges: true。
但我需要确保在查询 QuerySnapshot 时获得元数据。我将query 用于stream 而不是addSnapshotListener。
像这样:
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);
},
),
我已经尝试指定:
query: Firestore.instance.collection('Collection')
.snapshots(includeMetadataChanges: true),
但这不可能:
错误:未定义命名参数“includeMetadataChanges”。
我也试试:
snapshot.getMetadata().hasPendingWrites()
但是报错:
错误:没有为类定义方法“getMetaData” '文档快照'。
有谁知道在 Flutter 中如何做到这一点?有可能吗?
我尝试了这么久,但找不到方法..帮助!
谢谢!
【问题讨论】:
标签: firebase dart google-cloud-platform flutter google-cloud-firestore