[英]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.