global_state 0.1.2 global_state: ^0.1.2 copied to clipboard
Simplistic state management paradigm. Global State automatically refresh Widgets on data changes.
Global State #
This package is outdated and not mantained anymore. Use Floop library instead.
Global State is an automatic Widget refresh library for Flutter. Inspired by react-recollect.
Example - How to use #
-class Clicker extends StatelessWidget {
+class Clicker extends StatelessWidgetGS {
@override
-Widget build(BuildContext context) {
+Widget buildGS(BuildContext context) {
return Scaffold(
body: Center(
+ child: Text(store['clicks'].toString())
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
+ onPressed: () => store['clicks']++ // change 'clicks' from anywhere in the app and the widget will get updated
),
);
}
}
store
is an ObservedMap
instance that comes bundled in with the library. Own 'stores' can be created if preferred: Map myStore = ObservedMap();
.
When a value in the 'store' changes, GlobalState will only rebuild the Widgets that used that value.
More #
Global State is a wrapper library over Floop. It does exactly the same with a different name.
Check the github repository for more details, examples and up to date information: