listener property

void Function(S state)? listener
finalinherited

Function to execute when state changes without triggering a rebuild.

This is useful for side effects like navigation, showing dialogs, or logging. The listener is called whenever the state changes and listenWhen returns true.

Example:

NotifierListener<CounterNotifier, int>(
  listener: (state) {
    if (state > 10) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('Count exceeded 10!'))
      );
    }
  },
  child: MyWidget(),
)

Implementation

final void Function(S state)? listener;