Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.25 KB

README.md

File metadata and controls

54 lines (41 loc) · 1.25 KB

Simple State Management

A state management solution that is light weight, easy to use, and performant. Uses Flutter's InheritedNotifier.

Features

  • Ridiculously easy to use.
  • Light weight & performant.
  • Lazily load data.

Usage

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: ...,
        );
    }),
);