synckit 0.2.6
synckit: ^0.2.6 copied to clipboard
A Package to Sync data b/w Network and Local Storage.
SyncKit #
SyncKit is a Dart package designed to facilitate seamless synchronization of data between local storage and network storage. It provides a robust and flexible framework for managing data synchronization in Flutter applications.
Features #
- Local and Network Storage: Sync data between local storage (Hive) and network storage (Firestore).
- Sorting and Filtering: Configurable sorting and filtering of datasets.
- Initialization Callbacks: Custom initialization logic with callbacks.
- Error Handling: Comprehensive error handling for network and storage operations.
- Riverpod Integration: Easily integrate with Riverpod for state management.
Getting Started #
To start using SyncKit, run the following command:
flutter pub add synckit
This will add the latest version of SyncKit to your pubspec.yaml and install the package.
Usage #
Basic Setup #
-
Define your data model:
class MyDataModel with StdObj { @override final String id; final String name; MyDataModel({required this.id, required this.name}); @override Map<String, dynamic> toJson() => {'id': id, 'name': name}; factory MyDataModel.fromJson(Map<String, dynamic> json) => MyDataModel(id: json['id'], name: json['name']); } -
Initialize SyncManager:
final syncManager = SyncManager<MyDataModel>.fromStdObj( fromJson: MyDataModel.fromJson, storage: LocalStorage<MyDataModel>('my_data_box'), network: NetworkStorage<MyDataModel>('my_data_collection'), ); -
Create SyncConfig:
final syncConfig = SyncConfig<MyDataModel>( manager: syncManager, sortConfig: SortConfig(isSorted: true, comparator: (a, b) => a.name.compareTo(b.name)), ); -
Use with Riverpod:
@riverpod class MyDataNotifier extends _$MyDataNotifier with SyncedState<MyDataModel> { @override MyDataModel build() { return initialize(syncConfig); } }
Advanced Usage #
-
Custom Initialization Callback:
syncConfig.initializeCallback = (state, obj) async { // Custom initialization logic }; -
Handling Errors:
try { await syncManager.update(data); } catch (e) { // Handle error }
Additional Information #
For more information, visit the documentation. Contributions are welcome! Please see the contributing guidelines for more details. If you encounter any issues, please file them here.