A fork of Simple State Management
A dead simple state management using InheritedNotifier.
- Ridiculously easy to use.
- Light weight & performant.
- Lazily creating state.
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,
...
);