globalstore

Last updated:

0 purchases

globalstore Image
globalstore Images
Add to Cart

Description:

globalstore

globalstore #
##Methods
context.initState("key", "value"); // initial state
context.get("key"); //get value from state !! null if not initialized !!
context.update("key", "new value"); // update state
context.subscribe("key", callback); // subscribe to the store !! notifying callback every time the value of key is changed return unsubscribe method
copied to clipboard
##Example:
class Example extends StatefulWidget {
const Example({super.key});

@override
State<Example> createState() => _ExampleState();
}

class _ExampleState extends State<Example> {
int _counter = 0;
Function unsubscribe = () {};

@override
void initState() {
// TODO: implement initState
_counter = context.get("counter");
super.initState();
unsubscribe = context.subscribe("counter", () {
setState(() {
_counter = context.get("counter");
});
});
}

@override
void dispose() {
// TODO: implement dispose
super.dispose();
unsubscribe();
print(context);
}

@override
Widget build(BuildContext context) {
return Text(
"${_counter}",
style: Theme.of(context).textTheme.headline4,
);
}
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.