Skip to content

Offline Mutations

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

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'),
);
},
)
OptionTypeDefaultDescription
queueWhenOfflineboolfalseIf true, stores the mutation if network is unavailable.
maxRetriesint0Number of times to retry the mutation when syncing.

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

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

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

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

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

await OfflineQueueManager.instance.processQueue();