hydrated_notifier 1.0.1 icon indicating copy to clipboard operation
hydrated_notifier: ^1.0.1 copied to clipboard

An extension to the state_notifier library which automatically persists and restores states.

Hydrated Notifier #

Features #

An extension to the state_notifier library which automatically persists and restores states built on top of hive.

Usage #

Setup HydratedStorage #

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  /// Initialize storage
  HydratedStateNotifier.storage = await HydratedStorage.build(
    storageDirectory: kIsWeb
        ? HydratedStorage.webStorageDirectory
        : await getTemporaryDirectory(),
  );

  runApp(App())
}

Create a HydratedStateNotifier #

class CounterNotifier extends HydratedStateNotifier<int> {
  CounterNotifier() : super(0);

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

  @override
  int fromJson(Map<String, dynamic> json) => json['value'] as int;

  @override
  Map<String, int> toJson(int state) => { 'value': state };
}

Now the CounterNotifier will automatically persist/restore their state. We can increment the counter value, hot restart, kill the app, etc... and the previous state will be retained.

Additional information #

This is a fork of hydrated_bloc.

2
likes
100
pub points
53%
popularity

Publisher

verified publisher iconherve-guigoz.com

An extension to the state_notifier library which automatically persists and restores states.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

flutter, hive, state_notifier, synchronized

More

Packages that depend on hydrated_notifier