listen method

void listen(
  1. BuildContext context,
  2. void callback(), {
  3. 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

void listen(
  BuildContext context,
  void Function() callback, {
  String? debugLabel,
}) {
  listenSignal<T>(
    context,
    this,
    callback,
    debugLabel: debugLabel,
  );
}