Additional DataStore methods
Clear
To stop DataStore sync process and to clear local data from DataStore, use the clear
method:
Future<void> clearStore() async { try { await Amplify.DataStore.clear(); print('DataStore is cleared.'); } on DataStoreException catch (e) { print('Failed to clear DataStore: $e'); }}
Start
Synchronization starts automatically whenever you run any DataStore operation (query()
, save()
, delete()
, observe()
.) You can also explicitly begin the process with DataStore.start()
:
Future<void> startStore() async { try { await Amplify.DataStore.start(); print('DataStore is started.'); } on DataStoreException catch (e) { print('Failed to start DataStore: $e'); }}
Stop
To stop the DataStore sync process, you can use DataStore.stop()
. This will close the real time subscription connection when your app is no longer interested in updates. You will typically call DataStore.stop()
just before your application is closed. You can also force your DataStore sync expressions to be re-evaluated at runtime by calling stop()
followed by start()
.
Future<void> stopStore() async { try { await Amplify.DataStore.stop(); print('DataStore is stopped.'); } on DataStoreException catch (e) { print('Failed to stop DataStore: $e'); }}