I am building a Flutter app with ObjectBox database.
App calls openStore(); at launch, and saves the Store instance in a singleton class so that I can access to it from anywhere.
But I'm not sure when to call store.close();
In iOS we can execute code right before app termination using applicationWillTerminate(_:)
Unfortunately, Flutter does not provide us something like this.
I tried below code in the longest live expected StatefulWidget but it sometimes dispose sooner and the app loses access to the database.
@override
void dispose() {
StoreHelper().store?.close();
super.dispose();
}
My questions are...
- What's the best practice to call store.close()?
- What happen if I don't close the store? Would my app lose data persistency?