Docs

Dart: Offline

Cache reads and queue writes while the device is offline, then sync in order; kept on disk by default with the Dart and Flutter SDK.

Updated Oct 24, 2026

Cache reads and queue writes while the device is offline, then sync in order; kept on disk by default. Every call runs as the client's signed-in user, so your project's policies and row-level security apply. Types and members are listed in source order; each one links to its HTTP endpoint where it maps to one.

#Types and members

OfflineStore

A small key/value store for the offline cache and write queue. The default (FileOfflineStore) keeps it in files in the app's private data folder, so it survives a relaunch; pass MemoryOfflineStore to keep it for this run only, or your own store (e.g. encrypted) for anything else.

abstract class OfflineStore

OfflineStore.get

Future<String?> get(String key)

OfflineStore.set

Future<void> set(String key, String value)

OfflineStore.delete

Future<void> delete(String key)

OfflineStore.keys

Keys that start with prefix.

Future<List<String>> keys(String prefix)

MemoryOfflineStore

Keeps the offline cache and queue for this run only: queued writes not yet synced are lost on relaunch.

class MemoryOfflineStore implements OfflineStore

MemoryOfflineStore.get

Future<String?> get(String key)

MemoryOfflineStore.set

Future<void> set(String key, String value)

MemoryOfflineStore.delete

Future<void> delete(String key)

MemoryOfflineStore.keys

Future<List<String>> keys(String prefix)

SovariaOffline

Offline-first for the data API: when a request fails for lack of network, writes are queued (oldest first) and select/sql reads fall back to the last cached result. On reconnect the queue is replayed one request at a time, in order; a write the server refuses (a rule, a precondition) is dropped and reported to onSyncError. Mirrors the Swift and Kotlin offline controllers, scoped to this SQL-first client.

class SovariaOffline

SovariaOffline.SovariaOffline

Create an instance.

SovariaOffline(this._client,
    {required this.store, String? namespace, this.onSyncError, this.onSynced})
    : _ns

SovariaOffline.store

A property.

final OfflineStore store

SovariaOffline.Function

final void Function(SovariaException error, Map<String, Object?> write)? onSyncError

SovariaOffline.Function

final void Function(int count)? onSynced

SovariaOffline.maxQueued

Writes waiting at once; past this a new offline write is refused with OFFLINE_QUEUE_FULL instead of growing the store without bound (SDK2-M14).

static const maxQueued

SovariaOffline.maxCached

Cached read results kept; the oldest are dropped past this (SDK2-M14).

static const maxCached

SovariaOffline.online

False after a request failed for lack of network; true after one reached the server.

bool get online

SovariaOffline.writeOrQueue

Run a write, or queue it if there is no network.

Future<Object?> writeOrQueue(Map<String, Object?> body)

Returns the server's response, or a queued marker.

The same Idempotency-Key is used for the first try and every replay: a write the server applied whose answer was lost is not run twice when the queue is flushed (audit SDK2-M4).

SovariaOffline.readOrCache

Run a read, caching the result; on a network failure return the last cached result if there is one.

Future<Object?> readOrCache(String key, Future<Object?> Function() run)

SovariaOffline.pendingWrites

Writes queued offline that haven't reached the server yet, oldest first.

Future<List<Map<String, Object?>>> pendingWrites()

SovariaOffline.flush

Send queued writes now (also runs on reconnect and every 30 s while some are pending).

Future<int> flush()

Returns how many synced.

SovariaOffline.clear

Forget the cache and the queue (e.g.

Future<void> clear()

on sign-out).

SovariaOffline.migrate

Copy the offline entries (sov: keys) of from into to, keeping any to already has.

static Future<int> migrate(OfflineStore from, OfflineStore to, {String prefix = ""})

Use it when an app that kept its offline queue in one store moves to another (for example from MemoryOfflineStore to the persistent default), before calling Sovaria.enableOffline with to. Returns how many entries were copied.

SovariaOffline.close

Stop the background sync timer.

void close()

FileOfflineStore

An OfflineStore kept in files: one small file per key in directory, written to a temporary file first and then renamed, so a crash mid-write never leaves a half-written entry. The default directory is the app's private data folder (see FileOfflineStore.defaultDirectory). If the folder can't be created or written (a read-only or sandboxed location), the store keeps working in memory for this run and isPersistent turns false, rather than failing the app's requests.

class FileOfflineStore implements OfflineStore

FileOfflineStore.FileOfflineStore

Create an instance.

FileOfflineStore({String? directory}) : directory

FileOfflineStore.directoryOverride

Where every default store keeps its files.

static String? directoryOverride

Set it before Sovaria.enableOffline to choose the folder, for example in Flutter: FileOfflineStore.directoryOverride = '${(await getApplicationSupportDirectory()).path}/sovaria-offline'.

FileOfflineStore.directory

A property.

final String directory

FileOfflineStore.isPersistent

False when the folder couldn't be written and this run keeps entries in memory only.

bool get isPersistent

FileOfflineStore.defaultDirectory

The default folder: directoryOverride, else SOVARIA_OFFLINE_DIR, else the platform's app-data folder (Android: the app's files folder; iOS/macOS: Application Support; Windows: %APPDATA%; Linux: $XDG_DATA_HOME or ~/.local/share), each with sovaria/offline appended.

static String defaultDirectory()

FileOfflineStore.get

Future<String?> get(String key)

FileOfflineStore.set

Future<void> set(String key, String value)

FileOfflineStore.delete

Future<void> delete(String key)

FileOfflineStore.keys

Future<List<String>> keys(String prefix)

defaultOfflineStore

The offline store Sovaria.enableOffline uses when none is given: files in the app's private data folder, so cached reads and queued writes survive a relaunch.

OfflineStore defaultOfflineStore()

Web builds keep the cache in memory.

FileOfflineStore

Files aren't available on this platform (the web); use MemoryOfflineStore or your own OfflineStore.

class FileOfflineStore implements OfflineStore

FileOfflineStore.FileOfflineStore

Create an instance.

FileOfflineStore({String? directory})

FileOfflineStore.directoryOverride

A property.

static String? directoryOverride

FileOfflineStore.directory

A property.

String get directory

FileOfflineStore.isPersistent

A property.

bool get isPersistent

FileOfflineStore.defaultDirectory

static String defaultDirectory()

FileOfflineStore.get

Future<String?> get(String key)

FileOfflineStore.set

Future<void> set(String key, String value)

FileOfflineStore.delete

Future<void> delete(String key)

FileOfflineStore.keys

Future<List<String>> keys(String prefix)

defaultOfflineStore

The offline store Sovaria.enableOffline uses when none is given.

OfflineStore defaultOfflineStore()

On the web there are no files: the cache is kept in memory (pass your own OfflineStore, e.g. one over IndexedDB, to keep it across reloads).