Offline-first cloud sync engine for Flutter — persistent outbox, retry with backoff & dead-letter, pull cursors, and pluggable conflict resolution over any backend (EN + বাংলা):
- Backend-agnostic — implement 2-method
CloudRemoteAdapter(pushBatch/pullChanges) or just pass two closures viaCallbackCloudAdapter; works with Firebase, Supabase, your own REST API - Persistent outbox — writes queue locally (
shared_preferences), survive restarts, flush in batches, back off on failure, and land in a dead-letter list after N attempts instead of looping forever - Hybrid-logical-clock ordering —
updatedAtUtc+hlcCounterkeeps edit order sane even with clock skew - Conflict strategies —
lastWriteWins,preferLocal,preferRemote(ConflictStrategy) - Incremental pull — per-collection cursors persist, so
pullChanges()only fetches what changed since last sync - Widgets + fakes included —
CloudSyncStatusPill,CloudSyncSettingsTile, andInMemoryCloudAdapterfor fast widget tests; EN / বাংলা viaCloudSyncStrings.bn()
dependencies:
smart_cloud_sync_kit:
git:
url: https://github.com/Keshab1997/smart_cloud_sync_kit.git
ref: mainimport 'package:smart_cloud_sync_kit/smart_cloud_sync_kit.dart';
// 1) Wire your backend with two closures:
final sync = await SmartCloudSyncController.create(
adapter: CallbackCloudAdapter(
onPushBatch: (records) => myApi.upsertAll(records),
onPullChanges: (collection, sinceUtc) => myApi.changes(collection, sinceUtc),
),
conflictStrategy: ConflictStrategy.lastWriteWins,
);
// 2) Write locally — queued offline, synced when possible:
await sync.enqueueUpsert(
collection: 'notes',
recordId: 'note-1',
payload: {'title': 'বাজারের লিস্ট', 'done': false},
);
await sync.enqueueDelete(collection: 'notes', recordId: 'note-2');
// 3) Sync when online (e.g. on app resume / connectivity change):
await sync.flushOutbox(); // push queued writes
final applied = await sync.pullChanges( // fetch remote changes
collection: 'notes',
onApplyRecord: (record) async => db.apply(record),
readLocalRecord: (id) => db.read(id), // optional, for conflict checks
);
// 4) Show status in the UI:
CloudSyncStatusPill(controller: sync, strings: const CloudSyncStrings.bn());
CloudSyncSettingsTile(controller: sync); // pending count + "sync now"In widget tests swap the backend for InMemoryCloudAdapter() — no network, no mocks.
| Symbol | What it does |
|---|---|
SmartCloudSyncController.create({adapter, conflictStrategy, batchSize, maxAttemptsBeforeDeadLetter}) |
restores persisted outbox + cursors |
enqueueUpsert / enqueueDelete |
offline-safe local writes (tombstones for deletes) |
flushOutbox({ignoreBackoff}) / pullChanges(...) / retryDeadLetters() |
sync operations |
isSyncing, pendingCount, deadLetterCount, lastSyncedAt, lastError |
live state for UI |
CloudRemoteAdapter / CallbackCloudAdapter / InMemoryCloudAdapter |
backend port + test fake |
CloudSyncRecord / OutboxEntry / ConflictStrategy / CloudConflictResolver |
data model & merge logic |
CloudSyncStatusPill / CloudSyncSettingsTile |
Material 3 status UI |
CloudSyncStrings / CloudSyncStrings.bn() |
all labels, English / বাংলা |