Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 是否可以从Firestore快照获取元数据?_Firebase_Dart_Google Cloud Platform_Flutter_Google Cloud Firestore - Fatal编程技术网

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.9cloud\u firestore包中添加了对
includeMetadataChanges
参数的颤振支持

调用
snapshots()
函数时,现在可以将其作为参数包含

此示例返回集合中所有文档的流,作为联系人列表。如果
includeMetadataChanges
false(默认行为),则元数据更改时(例如hasPendingWritesisFromCache)流将不会更新。如果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())
}