listen method
- @Deprecated('use SignalsMixin in StatefulWidget')
- BuildContext context,
- void 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) {
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
@Deprecated('use SignalsMixin in StatefulWidget')
void listen(
BuildContext context,
void Function() callback, {
String? debugLabel,
}) {
listenSignal<T>(
context,
this,
callback,
debugLabel: debugLabel,
);
}