Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 internet connection again.

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 internet connection is gained. 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?

Does Firestore have offline contingency for if the phone's battery dies before it could sync with Firestore?

Or is there another solution I am unaware of?

like image 557
Pieter Pienaar Avatar asked Jan 26 '26 00:01

Pieter Pienaar


2 Answers

For Android and iOS, offline persistence is enabled by default. You don't have to do anything in your code.

Note there is a default cache size of 100 MB. This can be changed though, eg

let settings = Firestore.firestore().settings
settings.cacheSizeBytes = FirestoreCacheSizeUnlimited
Firestore.firestore().settings = settings
like image 72
thomas gotzsche Avatar answered Jan 28 '26 16:01

thomas gotzsche


Does Firestore have offline contingency for if the phone's battery dies before it could sync with 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. This disk based cache will survive restarts of the app/reloads of the page.

like image 31
Frank van Puffelen Avatar answered Jan 28 '26 17:01

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!