pub package

StateScope

A fork of 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 StateScope.

StateScope(
    create: () => AppState(),
    child: ...
);

Data is lazily-loaded by default. To disable and load immediately when StateScope is built, set lazy to false.

StateScope(
    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 StateScope.value.

final appState = context.read<AppState>();
Navigator.of(context).push(
    MaterialPageRoute(builder: (context) {
        return StateScope.value(
            value: appState,
            child: ...,
        );
    }),
);

Libraries

statescope
A simple state management based on InheritedNotifier.