hive_cubit 0.0.1 copy "hive_cubit: ^0.0.1" to clipboard
hive_cubit: ^0.0.1 copied to clipboard

A lightweight HiveCubit that auto-persists Cubit state to a Hive box with zero boilerplate.

example/hive_cubit_example.dart

import 'package:hive/hive.dart';
import 'package:hive_cubit/hive_cubit.dart';

// A minimal example showing HiveCubit outside of a Flutter UI.
// In a real Flutter app, wrap this cubit with BlocBuilder/BlocProvider
// as usual — HiveCubit is a drop-in replacement for Cubit.

class CounterCubit extends HiveCubit<int> {
  CounterCubit()
      : super(boxName: 'example_box', key: 'counter', initialState: 0);

  void increment() => updateState(state + 1);
}

Future<void> main() async {
  Hive.init('./.example_hive_data');

  final cubit = CounterCubit();
  await cubit.ready; // loads any previously persisted count

  print('Starting count: ${cubit.state}');

  cubit.increment();
  cubit.increment();

  print('Count after two increments: ${cubit.state}');
  print('Run this example again — the count will keep increasing,');
  print('because it is now persisted to disk.');

  await cubit.close();
}
0
likes
0
points
159
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight HiveCubit that auto-persists Cubit state to a Hive box with zero boilerplate.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

bloc, hive

More

Packages that depend on hive_cubit