listenWhen property

ListenerCondition<T>? listenWhen
final

An optional listenWhen can be implemented for more granular control over when listener is called. listenWhen will be invoked on each stateNotifier state change. listenWhen takes the previous state and current state and must return a bool which determines whether or not the listener function will be invoked. The previous state will be initialized to the state of the stateNotifier when the LidListener is initialized. listenWhen is optional and if omitted, it will default to true.

LidListener<StateType>(
  stateNotifier: stateNotifier,
  listenWhen: (previous, current) {
    // return true/false to determine whether or not
    // to invoke listener with state
  },
  listener: (context, state) {
    // do stuff here based on State Notifier's state
  }
  child: Container(),
)

Implementation

final ListenerCondition<T>? listenWhen;