offline_sync_helper 1.0.1 copy "offline_sync_helper: ^1.0.1" to clipboard
offline_sync_helper: ^1.0.1 copied to clipboard

A fully customizable offline-first sync engine for Flutter apps with support for Hive, Drift, and custom storage adapters.

๐Ÿ“ก offline_sync_helper #

Pub Version Pub Likes Pub Points Pub Popularity GitHub Stars GitHub Forks GitHub Issues License Platform Null Safety

A fully customizable offline-first sync engine for Flutter apps.

offline_sync_helper simplifies the process of working with local data, tracking changes, and syncing them with a remote backend. It offers built-in support for Hive, Drift, Firebase, and is extensible to any local storage system or API format.


๐Ÿงฉ Why offline_sync_helper? #

Building apps that work offline and sync intelligently when online is a pain for most developers.

This package provides:

  • โœ… Easy offline storage integration
  • โœ… Automatic background sync when connectivity is restored
  • โœ… Customizable conflict resolution strategies
  • โœ… Full control over local/remote adapters and sync flows

๐Ÿš€ Features #

  • ๐ŸŒ Offline-first architecture
  • ๐Ÿ”„ Automatic sync on app launch, connectivity change, or manual trigger
  • ๐Ÿง  Change tracking for inserts, updates, deletes
  • ๐Ÿ› ๏ธ Pluggable adapters for local and remote storage
  • ๐Ÿงฉ Conflict resolution strategies: client wins, server wins, timestamp, or custom
  • ๐Ÿ”’ Encrypted local storage support (via Hive)
  • ๐Ÿ“ถ Connectivity-aware retry mechanism
  • ๐Ÿงช Testable architecture with mock support
  • ๐Ÿ”ค Arabic & RTL support

๐Ÿ“ฆ Installation #

Add the package to your pubspec.yaml:

dependencies:
  offline_sync_helper: ^1.0.0
  connectivity_plus: ^5.0.2
  hive: ^2.2.3
  http: ^1.2.1
  path_provider: ^2.1.2

You can replace Hive with Drift, Firebase, or other local storage plugins based on your adapter implementation.


๐Ÿ› ๏ธ Getting Started #

1. Initialize the Sync Engine #

import 'package:offline_sync_helper/offline_sync_helper.dart';

await OfflineSyncHelper.initialize(
  localAdapter: HiveAdapter<Task>(),
  remoteSyncService: ApiSyncService(),
  conflictResolver: TimestampResolver(),
);

2. Save Data Locally #

await OfflineSyncHelper.save(
  model: Task(id: 1, name: 'Collect Feedback'),
);

The change is stored locally and synced automatically when the device goes online.


๐Ÿงฑ Architecture Overview #

+-------------------+
| LocalAdapter      |<------- Hive / Drift / Firebase
+-------------------+
         |
         โ–ผ
+-------------------+           +---------------------+
| SyncManager       |<--------->| RemoteSyncService   |
+-------------------+           +---------------------+
         |
         โ–ผ
+-------------------+
| ConflictResolver  |<--- Custom, Timestamp, Client, Server
+-------------------+

๐Ÿ”Œ Adapter Interfaces #

Local Adapter #

abstract class LocalAdapter<T> {
  Future<void> saveLocally(T model);
  Future<List<T>> getPendingChanges();
  Future<void> markAsSynced(List<T> models);
}

Remote Sync Service #

abstract class RemoteSyncService<T> {
  Future<SyncResult> sync(List<T> models);
}

โš”๏ธ Conflict Resolution #

Built-in options:

  • ClientWinsResolver โ€“ local data always overwrites remote
  • ServerWinsResolver โ€“ remote data always overwrites local
  • TimestampResolver โ€“ newer data (based on timestamp) wins

Create your own:

class CustomResolver implements ConflictResolver<Task> {
  @override
  Task resolve(Task local, Task remote) {
    return local.priority > remote.priority ? local : remote;
  }
}

๐Ÿ” Sync Triggers #

  • App launch
  • Internet reconnect
  • Manual syncNow() method
  • Periodic background task (coming soon)

๐Ÿ”’ Secure Local Storage #

Hive supports AES encryption. To enable:

var box = await Hive.openBox(
  'tasks',
  encryptionCipher: HiveAesCipher(my32ByteKey),
);

๐Ÿ›  Configuration Options #

OfflineSyncHelperConfig(
  retryPolicy: RetryPolicy.maxAttempts(3),
  batchSize: 20,
  syncInterval: Duration(minutes: 5),
  enableConnectivityWatcher: true,
  autoSyncOnConnectivityChange: true,
);

๐Ÿ“ฑ Supported Platforms #

  • โœ… Android
  • โœ… iOS

๐ŸŒ Internationalization #

Supports:

  • RTL layouts
  • Arabic and multi-language labels
  • intl package compatibility

๐Ÿ“š Example Use Cases #

Use Case Description
Field Agent App Collect data in remote areas, sync later
Delivery Tracker Update delivery statuses offline
E-Commerce Cart Allow cart actions without internet
CRM / Lead Tracker Sales staff update records offline

๐Ÿ“‚ Full Example
For a complete working example with multiple field types, custom themes, and step-by-step forms, check out:
๐Ÿ‘‰ Full Example on GitHub

License #

MIT

Author #

sdkwala.com

5
likes
120
points
31
downloads

Publisher

verified publishersdkwala.com

Weekly Downloads

A fully customizable offline-first sync engine for Flutter apps with support for Hive, Drift, and custom storage adapters.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

connectivity_plus, flutter, hive, http, path_provider

More

Packages that depend on offline_sync_helper