flutter_state_notifier 0.6.1

Flutter Android iOS web

Flutter bindings for state_notifier, such as StateNotifierProvider and StateNotiferBuilder

pub package

Welcome to flutter_state_notifier~

This repository is a side-package that is destined to be used together with state_notifier.

It adds extra Flutter bindings to StateNotifier, such as provider integration.

The available widgets #

StateNotifierProvider #

StateNotifierProvider is the equivalent of ChangeNotifierProvider but for StateNotifier.

Its job is to both create a StateNotifier and dispose it when the provider is removed from the widget tree.

If the created StateNotifier uses LocatorMixin, StateNotifierProvider will also do the necessary to make read/update work with provider.

It is used like most providers, with a small difference:
Instead of exposing one value, it exposes two values at the same time:

Which means that when you write:

class MyState {}

class MyStateNotifier extends StateNotifier<MyState> {
  MyStateNotifier(): super(MyState());
}

// ...

MultiProvider(
  providers: [
    StateNotifierProvider<MyStateNotifier, MyState>(create: (_) => MyStateNotifier()).
  ]
)

This allows you to both:

  • obtain the StateNotifier in the widget tree, by writing context.read<MyStateNotifier>()
  • obtain and observe the current [MyState], through context.watch<MyState>()

StateNotifierBuilder #

StateNotifierBuilder is equivalent to ValueListenableBuilder from Flutter.

It allows you to listen to a StateNotifier and rebuild your UI accordingly, but does not create/dispose/provide the object.

As opposed to StateNotifierProvider, this will not make read/update of StateNotifier work.

It is used as such:

class MyState {}

class MyStateNotifier extends StateNotifier<MyState> {
  MyStateNotifier(): super(MyState());
}

// ...

MyStateNotifier stateNotifier;

return StateNotifierBuilder<MyState>(
  stateNotifier: stateNotifier,
  builder: (BuildContext context, MyState state, Widget child) {
    return Text('$state');
  },
)
22
likes
110
pub points
93%
popularity

Flutter bindings for state_notifier, such as StateNotifierProvider and StateNotiferBuilder

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

darky12s@gmail.com

License

MIT (LICENSE)

Dependencies

flutter, meta, provider, state_notifier

More

Packages that depend on flutter_state_notifier