watcher_builder

Creator: coderz1093

Last updated:

0 purchases

watcher_builder Image
watcher_builder Images

Languages

Categories

Add to Cart

Description:

watcher builder

NEW! #
With version 1.1.0 now you can create a VarWatcher instance of any type using the getter .watch which will make it easy for you to watch your variable. In addition, with 1.1.0 you can build watchers with much simpler methods. For example, you can
invoke .build() method on your watcher and pass in the builder function.
final watcher = 0.watch;
// This will rebuild automaticlly whenever notify is invoked on watcher
Widget watcherBuilder = watcher.build((value) => Text('value = $value'));
copied to clipboard
Furthermore, we made builder even simpler by introducing a new operator on VarWatcher.
Widget simple = watcher >> (value) => Text('value = $value');
copied to clipboard
Similarly, if you declare a list of VarWatchers you can also invoke the same method and operator.
final watchers = [
0.watch,
0.watch,
0.watch,
];
Widget watchersBuilder = watchers.build(
() => Column(children: watchersBuilder.map((w) =>
Text('value = ${w.value}')).toList()));
// or
Widget simple2 = watchers >> Column(children: watchersBuilder.map((w) =>
Text('value = ${w.value}')).toList());
copied to clipboard
Features #
WatcherBuilder is the simplest state management in flutter. All you have to do
is declare a VarWatcher, use it inside a WatcherBuilder and call notify anytime
you want to update/rebuild its widget.
Usage #
@override
Widget build(BuildContext context) {
final counter = VarWatcher(0);
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
WatcherBuilder(
watch: counter,
builder: (context, value) => Text('Counter = $value'),
),
OutlinedButton(
onPressed: () {
counter.value++;
counter.notify();
},
child: const Text('Increment'),
)
],
),
),
);
}
copied to clipboard
Additional information #
You can also use WatchersBuilder if you want to watch multiple VarWatchers

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.