Skip to content
/ statescope Public

A dead simple state management using InheritedNotifier

License

Notifications You must be signed in to change notification settings

1l0/statescope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A dead simple state management using InheritedNotifier

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published