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