Skip to content

burhanaksendir/simple_state_management

 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 63.9%
  • HTML 31.5%
  • Swift 3.2%
  • Kotlin 1.1%
  • Objective-C 0.3%