A state management solution that is light weight, easy to use, and performant. Uses Flutter's InheritedNotifier.
- Ridiculously easy to use.
- Light weight & performant.
- Lazily load data.
Store state in a class that extends ChangeNotifier, then create with Provider.
Provider(
create: () => AppState(),
child: ...
);Data is lazily-loaded by default. To disable and load immediately when Provider is built, set lazy to false.
Provider(
create: () => AppState(),
lazy: false,
child: ...
);Access state via BuildContext wherever needed.
// DO rebuild widget when state changes.
context.watch<AppState>();
// DO NOT rebuild widget when state changes.
context.read<AppState>();Pass data that has already been instantiated between BuildContexts by using Provider.value.
final appState = context.read<AppState>();
Navigator.of(context).push(
MaterialPageRoute(builder: (context) {
return Provider.value(
value: appState,
child: ...,
);
}),
);