简体   繁体   English

当我在 flutter firestore 中打开互联网时,我如何知道我在离线模式下对文档所做的所有更改都同步到了 firestore

[英]How do i know all my changes made to document in offline mode are synced to firestore when i turn on internet in flutter firestore

I am creating flutter app , where I am using Cloud Firestore as a database and I am utilizing its offline capability.我正在创建flutter 应用程序,其中我使用Cloud Firestore作为数据库,并且正在利用其离线功能。 the app perfectly works when I am in offline mode it saves documents locally and when I turn on the internet it syncs those documents back to Firestore.该应用程序在我处于离线模式时完美运行,它在本地保存文档,当我打开互联网时,它会将这些文档同步回 Firestore。

I want to know is there any way to know that all of my documents are synced when I turn on the internet, like some event listener or something?我想知道当我打开互联网时,有什么方法可以知道我的所有文档都已同步,比如一些事件监听器之类的?

I didn't find anything in the documentation.我在文档中没有找到任何东西。

I want to know if is there any way to know that all of my documents are synced when I turn on the internet, like some event listener or something?我想知道是否有任何方法可以知道当我打开互联网时我的所有文档都已同步,例如某些事件侦听器之类的?

Yes, you can know that in Flutter too.是的,您也可以在 Flutter 中知道。 So please check the SnapshotMetadata of a QuerySnapshot object, which contains an isFromCache field that:因此,请检查QuerySnapshot object 的SnapshotMetadata ,其中包含一个isFromCache字段:

Whether the snapshot was created from cached data rather than guaranteed up-to-date server data.快照是否是从缓存数据创建的,而不是保证最新的服务器数据。

If your Flutter project requires you to listen for metadata changes , then please check the official documentation:如果您的 Flutter 项目需要您监听元数据变化,请查看官方文档:

If you want to receive snapshot events when the document or query metadata changes, pass a listen to options object when attaching your listener:如果您想在文档或查询元数据更改时接收快照事件,请在附加侦听器时传递一个侦听选项 object:

final docIdRef = db.collection("collName").doc("docId");
docIdRef.snapshots(includeMetadataChanges: true).listen((event) {
  //Your logic.
});

In this way, you'll be able to update the UI elements of your screens, once the data is synchronized with the Firebase servers.通过这种方式,一旦数据与 Firebase 服务器同步,您就可以更新屏幕的 UI 元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 flutter 中获取 firestore 文档的 documentid? - How do I get documentid of a firestore document in flutter? _Future 的实例<int>当我试图在 Firestore 中获取我的“收藏”的全部“文档”时,我得到的就是这些</int> - Instance of _Future<int> is all I get when I try to get the total 'document' of my 'collection' in Firestore 如何获取在 flutter 中具有特定字段值的 Firestore 文档的 DocumentID? - How do I get the DocumentID of a firestore document that has a particular field value in flutter? 如何从 Firestore 获取文档 ID 列表 - How do I get a list of document ID’s from Firestore 如何使用 flutter 从 Firestore 获取子集合? - How do I fetch sub collection from firestore using flutter? Firestore:如何更新 email 并将其作为单个批处理操作存储在我的 Firestore 集合中? - Firestore: How do I update email and store it in my firestore collection as a single batch operation? 如何将我的 MAUI 应用程序连接到生产环境中的 Firestore 数据库? - How do I connect my MAUI app to a Firestore database in production? 如何知道 Firestore flutter 中重复条目的计数? - How to know the count of repeated entries in Firestore flutter? 如何遍历 Flutter 中的 Firestore 文档中的字段? - How to iterate through fields in a Firestore Document in Flutter? Firestore:我什么时候必须删除 SnapshotListener? - Firestore: When do I have to remove SnapshotListeners?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM