Skip to content

moo7md/watcher_builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'));

Furthermore, we made builder even simpler by introducing a new operator on VarWatcher.

Widget simple = watcher >> (value) => Text('value = $value');

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());

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'),  
)  
],  
),  
),  
);  
}  

Additional information

You can also use WatchersBuilder if you want to watch multiple VarWatchers

About

Simplest state management package for fluttr

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages