As far as I know Flutter Firestore operation will keep retry when the internet connectivity is down. Is there a way to set timeout duration so that Firestore throw an error in CatchError when it exceeds the timeout duration?
As far as I know Flutter Firestore operation will keep retry when the internet connectivity is down. Is there a way to set timeout duration so that Firestore throw an error in CatchError when it exceeds the timeout duration?
try this to handle a timeout at app initialization:
Future<FirebaseApp> app;
void appInit() {
app.timeout(Duration(seconds: 5), onTimeout: (){
// handle app timeout here
});
app = FirebaseApp.configure(
name: 'test',
options: const FirebaseOptions(
googleAppID: googleAppID,
gcmSenderID: projectID,
apiKey: apiKey,
projectID: projectID,
),
);
}
this will handle a transaction timeout:
Firestore.instance.runTransaction((Transaction tx) {
// handle transaction here
}).timeout(Duration(seconds: 5), onTimeout: () {
// handle transaction timeout here
});
Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data. When the device comes back online, Cloud Firestore synchronizes any local changes made by your app to the Cloud Firestore backend.
For that reason, if you are not dealing with transactions (atomic operations), then You don't need to await for Firestore acks, and you don't need to use timeouts at all!
Checkout this awesome video: https://youtu.be/oDvdAFP6OhQ?t=704
Firestore documentation: https://firebase.google.com/docs/firestore/manage-data/enable-offline
Whenever users go online again, their actions will take place immediately, so you want to make sure to use actions such as ArrayUnion on lists and Increment for numeric values.
Offline mode can be manually enabled for Web.