OmniKV: Hive CE

pub package

The official hive_ce adapter for OmniKV.

Installation

You must install both the adapter and the underlying storage package:

flutter pub add omni_kv omni_kv_hive_ce hive_ce

Quick Start

Initialize your KvGateway with the HiveCeKvAdapter:

import 'package:omni_kv/omni_kv.dart';
import 'package:omni_kv_hive_ce/omni_kv_hive_ce.dart';
import 'package:hive_ce/hive.dart';

Future<void> main() async {
  // Ensure Hive is initialized for your platform first!
  // await Hive.initFlutter();
  
  final box = await Hive.openBox<Object?>('settings');
  
  final kv = KvGateway(
    HiveCeKvAdapter(
      box,
      codec: const HiveCeKvCodec(prefix: 'my_app.'),
    ),
  );

  // Ready to use!
}

Features

  • Watchable Streams: Because Hive CE natively supports watching boxes, this adapter implements WatchableKvCapability. You can call .watch() on any key to get a continuous stream of changes.
  • Native Maps: Hive natively supports raw Maps and Lists. If you use ModelConverter.toMap() or RecordConverter.toMap() on your keys, data will be stored natively instead of being stringified to JSON.
  • Scoped Clearing: If you provide a prefix to the codec, calling kv.clear() will only delete keys that start with that prefix from the Hive box.

For full documentation on how to define keys and use the fluent API, see the core OmniKV package.

Libraries

omni_kv_hive_ce