cloud_sync_hive_adapter 0.0.1-rc.2
cloud_sync_hive_adapter: ^0.0.1-rc.2 copied to clipboard
A Flutter plugin for integrating Hive sync functionality.
CloudSyncHiveAdapter #
A local storage implementation of the SyncAdapter
interface from the cloud_sync
package, built on top of Hive.
This adapter allows your app to store and sync note metadata and content locally using the Hive database.
β¨ Features #
- πΎ Persists metadata (
SyncMetadata
) and detailed content (String
) locally using Hive. - π Supports reading, writing, and syncing note data.
- π§± Ideal for offline-first apps or local caching alongside cloud sync (e.g., Google Drive).
- π Fast, lightweight, and key-value based local database.
π¦ Installation #
Add these dependencies to your pubspec.yaml
:
dependencies:
hive_ce: ^latest
cloud_sync: ^latest
cloud_sync_hive_adapter: ^latest
β οΈ Note: Be sure to initialize Hive before usage and register any adapters needed for your metadata class.
π Usage #
import 'package:hive_ce/hive.dart';
import 'package:cloud_sync_hive_adapter/cloud_sync_hive_adapter.dart';
import 'your_models/sync_metadata.dart'; // Your custom SyncMetadata
void main() async {
await Hive.initFlutter();
// Optionally register Hive adapters if needed
// Hive.registerAdapter(MyMetadataAdapter());
final metadataBox = await Hive.openBox<String>('metadataBox');
final detailBox = await Hive.openLazyBox<String>('detailBox');
final adapter = CloudSyncHiveAdapter<MyMetadata>(
metadataBox: metadataBox,
detailBox: detailBox,
metadataToJson: (meta) => jsonEncode(meta.toJson()),
metadataFromJson: (json) => MyMetadata.fromJson(jsonDecode(json)),
);
// Use the adapter with a CloudSync instance
}
π Class Overview #
class CloudSyncHiveAdapter<M extends SyncMetadata>
extends SerializableSyncAdapter<M, String>
Parameters #
metadataBox
: ABox<String>
used to store serialized metadata.detailBox
: ALazyBox<String>
for storing note content.metadataToJson
/metadataFromJson
: Serialization logic for your metadata type.
β When to Use #
- π± You need local storage for notes, logs, or structured data.
- π΄ Offline-first behavior is important.
- π You want to combine local persistence with cloud sync (e.g., Google Drive).
π License #
MIT (or your project's license)
π Related #
cloud_sync
β Core sync abstractionhive_ce
β Lightweight key-value database