Skip to Content

Offline Mutations

Queue mutations when the device is offline and automatically sync them when connectivity is restored.

Usage

Enable queueWhenOffline in your MutationOptions.

MutationBuilder<Todo, String>( mutationFn: (text) => api.addTodo(text), options: MutationOptions( // 1. Enable queuing queueWhenOffline: true, // 2. Configure retries if syncing fails maxRetries: 3, ), builder: (context, state, mutate) { return ElevatedButton( onPressed: () => mutate('New Todo'), child: Text('Add Todo'), ); }, )

API

MutationOptions

OptionTypeDefaultDescription
queueWhenOfflineboolfalseIf true, stores the mutation if network is unavailable.
maxRetriesint0Number of times to retry the mutation when syncing.

NetworkStatus

Fasq listens to network connectivity automatically, but you can override it if needed.

// Manually report status (e.g. for testing) NetworkStatus.instance.setOnline(false);

Examples

Showing “Queued” UI

You can show the user that their action is pending sync.

if (state.isQueued) { return Text('Saved offline. Will sync when online.'); }

Manual Syncing

While Fasq syncs automatically when the network returns, you can trigger a sync manually.

await OfflineQueueManager.instance.processQueue();
Last updated on