hooks_state_notifier 1.0.0 copy "hooks_state_notifier: ^1.0.0" to clipboard
hooks_state_notifier: ^1.0.0 copied to clipboard

Flutter hooks for StateNotifier.

StateNotifier Hook #

build workflow codecov

This package provides a useStateNotifier hook similar to useValueListenable. There is also useCreateStateNotifier hook which creates a StateNotifier and automatically dispose it.

Usage #

// 1. Create your state notifier as usual.
class CounterNotifier extends StateNotifier<int> {
  CounterNotifier() : super(0);

  void increment() => state++;
  void decrement() => state--;
}

// 2. Extend hook widget
class ReadMeExample extends HookWidget {
  const ReadMeExample({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 3. Create your notifier (useCreateStateNotifier will dispose it)
    final notifier = useCreateStateNotifier(() => CounterNotifier());
    // 4. Listen to your state
    final state = useStateNotifier(notifier);
    
    //......
  }
}
9
likes
140
pub points
23%
popularity

Publisher

unverified uploader

Flutter hooks for StateNotifier.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_hooks, state_notifier

More

Packages that depend on hooks_state_notifier