Firebase 是否可以从Firestore快照获取元数据?
我需要获取Firebase 是否可以从Firestore快照获取元数据?,firebase,dart,google-cloud-platform,flutter,google-cloud-firestore,Firebase,Dart,Google Cloud Platform,Flutter,Google Cloud Firestore,我需要获取快照元数据,以便检查写入Firestore是否成功。我查看并看到有SnapshotMetadata和布尔hasPendingWrites()。但我找不到如何实施。没有开源dart项目使用过它 Firebase say可以使用:.onSnapshot/.addSnapshotListener来指定includeMetadataChanges:true 但我需要确保在查询QuerySnapshot时获得元数据。我正在使用query进行stream而不是addSnapshotListener
快照
元数据,以便检查写入Firestore是否成功。我查看并看到有SnapshotMetadata
和布尔hasPendingWrites()
。但我找不到如何实施。没有开源dart项目使用过它
Firebase say可以使用:.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);
},
),
但这是不可能的:
错误:未定义命名参数“includeMetadataChanges”
我还尝试:
snapshot.getMetadata().hasPendingWrites()
但请给出错误:
错误:未为类定义方法“getMetaData”
“文档快照”
有人知道在弗利特是怎么做到的吗?有可能吗
我试了这么久,却找不到办法。。救命啊
谢谢 看起来没有公开底层文档的元数据。我将在添加的。includeMetadataChanges参数中为其提交功能请求
在版本为0.12.9的cloud\u firestore包中添加了对includeMetadataChanges
参数的颤振支持
调用snapshots()
函数时,现在可以将其作为参数包含
此示例返回集合中所有文档的流,作为联系人列表。如果includeMetadataChanges
为false(默认行为),则元数据更改时(例如hasPendingWrites或isFromCache)流将不会更新。如果true,则流将通过这些更改进行更新
Stream<List<Contact>> getAllContactsStream() {
return Firestore.instance.collection('contacts')
.orderBy('name', descending: false)
.snapshots(includeMetadataChanges: true)
.map((snapshot) => snapshot.documents.map((document) => Contact.fromFirestore(document)).toList())
}
Stream getAllContactsStream(){
返回Firestore.instance.collection('联系人')
.orderBy('name',降序:false)
.快照(包括元数据更改:true)
.map((快照)=>snapshot.documents.map((文档)=>Contact.fromFirestore(文档)).toList())
}
使用单个文档快照,可以通过document.data
访问正常的Firestore数据。元数据可通过文档访问。元数据
Stream<List<Contact>> getAllContactsStream() {
return Firestore.instance.collection('contacts')
.orderBy('name', descending: false)
.snapshots(includeMetadataChanges: true)
.map((snapshot) => snapshot.documents.map((document) => Contact.fromFirestore(document)).toList())
}