listen method
Used to listen for updates on a signal but not rebuild the nearest element
final counter = signal(0);
...
@override
Widget build(BuildContext context) {
counter.listen(context, () {
if (counter.value == 10) {
final messenger = ScaffoldMessenger.of(context);
messenger.hideCurrentSnackBar();
messenger.showSnackBar(
const SnackBar(content: Text('You hit 10 clicks!')),
);
}
});
...
}
Implementation
void listen(
BuildContext context,
void Function() callback, {
String? debugLabel,
}) {
listenSignal<T>(
context,
this,
callback,
debugLabel: debugLabel,
);
}