statescope 3.0.0 copy "statescope: ^3.0.0" to clipboard
statescope: ^3.0.0 copied to clipboard

A dead simple state management using InheritedNotifier

pub package

StateScope #

A fork of Simple State Management

A dead simple state management using InheritedNotifier.

Features #

  • Ridiculously easy to use.
  • Light weight & performant.
  • Lazily creating state.

Usage #

Store state in a class that extends ChangeNotifier,

class Counter extends ChangeNotifier {
    int count = 0;
    void countUp() {
        count++;
        notifyListeners();
    }
}

then put it in the creator of StateScope.

StateScope(
    creator: () => Counter(),
    child: Builder(
        builder: (context) {
            // watch() DO rebuild when state changes.
            final counter = context.watch<Counter>();
            return Column(
                children: [
                    Text('${counter.count}'),
                    ElevatedButton(
                        onPressed:(){
                            // read() DO NOT rebuild when state changes.
                            context.read<Counter>().countUp();
                        },
                        child: Text('Cout up'),
                    ),
                ],
            );
        },
    );
);

State is lazily-created by default. To create state immediately with StateScope, set lazy to false.

StateScope(
    lazy: false,
    ...
);
2
likes
160
points
64
downloads

Publisher

verified publisheroykot.tokyo

Weekly Downloads

A dead simple state management using InheritedNotifier

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on statescope