简体   繁体   English

Flutter Firestore 离线数据库

[英]Flutter Firestore Offline Database

I have a clarifying question about Cloud Firestore and Flutter: I am making an app that users can create log entries of sort, which will be saved on Firebase. But they might make up to 30 entries offline, before they have inte.net connection again.我有一个关于 Cloud Firestore 和 Flutter 的澄清问题:我正在制作一个用户可以创建分类日志条目的应用程序,这些日志条目将保存在 Firebase 上。但是在他们再次连接到 inte.net 之前,他们可能会离线创建多达 30 个条目.

And I know that Firestore has an offline feature, with which any created documents can be viewed offline because it is saved in the order of logging, and then synced with the database when inte.net connection is gained.而且我知道 Firestore 有一个离线功能,任何创建的文档都可以离线查看,因为它是按照日志记录的顺序保存的,然后在获得 inte.net 连接时与数据库同步。 But it is absolutely crucial that these logs cannot be lost in my app before having a chance of uploading it.但绝对重要的是,这些日志在有机会上传之前不能在我的应用程序中丢失。 Is there a way to ensure that my app will not lose this data before connecting to Firebase again, or should I create a Sembast database on the device, and save a copy of everything, and then check that once in a while against the database?有没有办法确保我的应用程序在再次连接到 Firebase 之前不会丢失这些数据,或者我应该在设备上创建一个 Sembast 数据库,并保存所有内容的副本,然后偶尔检查一下数据库?

Does Firestore have offline contingency for if the phone's battery dies before it could sync with Firestore?如果手机的电池在与 Firestore 同步之前就没电了,Firestore 是否有离线应急措施?

Or is there another solution I am unaware of?或者还有其他我不知道的解决方案吗?

For Android and iOS, offline persistence is enabled by default. Android和iOS默认开启离线持久化。 You don't have to do anything in your code.您无需在代码中执行任何操作。

Note there is a default cache size of 100 MB.请注意,默认缓存大小为 100 MB。 This can be changed though, eg这可以改变,例如

let settings = Firestore.firestore().settings
settings.cacheSizeBytes = FirestoreCacheSizeUnlimited
Firestore.firestore().settings = settings

For new version of use below code -对于使用以下代码的新版本 -

FirebaseFirestore.instance.settings =
        Settings(cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED);

Does Firestore have offline contingency for if the phone's battery dies before it could sync with Firestore?如果手机的电池在与 Firestore 同步之前没电了,Firestore 是否有离线应急措施?

When Firestore's offline persistence is enabled, it stores data that your app has recently read, as well as any pending writes, to a database on the local device or browser.启用 Firestore 的离线持久性后,它会将您的应用最近读取的数据以及任何挂起的写入存储到本地设备或浏览器上的数据库中。 This disk based cache will survives restarts of the app/reloads of the page.此基于磁盘的缓存将在页面的应用程序/重新加载重新启动后继续存在。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM