NotifierListener<N extends BaseNotifier<S>, S extends Object?> constructor

const NotifierListener<N extends BaseNotifier<S>, S extends Object?>({
  1. required Widget child,
  2. required void listener(
    1. S state
    ),
  3. ShouldProceedCallback<S>? listenWhen,
  4. void onInit(
    1. N notifier
    )?,
  5. Key? key,
})

Creates a NotifierListener.

child is the static child widget. listener is called for side effects when the state changes. listenWhen is an optional predicate that determines whether to call listener when the state changes. onInit is an optional callback invoked with the notifier when the widget is initialized.

Note: Do not manually call the notifier's onInit() method here. The notifier itself will automatically trigger its own onInit() when it is created, so calling it again would result in duplicate invocations. Example (incorrect usage):

NotifierListener<Notifier, State>(
  // Do NOT do this:
  onInit: (notifier) => notifier.onInit(),
  listener: (context, state) {...},
  child: ...,
)

key is the widget key.

Implementation

const NotifierListener({
  required Widget super.child,
  required void Function(S state) super.listener,
  super.listenWhen,
  super.onInit,
  super.key,
});