LidConsumer<S> constructor

const LidConsumer<S>({
  1. Key? key,
  2. required LidWidgetListener<S> listener,
  3. required StateNotifier<S> stateNotifier,
  4. required LidWidgetBuilder<S> builder,
  5. ListenerCondition<S>? listenWhen,
  6. BuilderCondition<S>? buildWhen,
  7. bool animate = false,
  8. AnimatedSwitcherTransitionBuilder transitionBuilder = AnimatedSwitcher.defaultTransitionBuilder,
  9. Duration duration = const Duration(milliseconds: 300),
})

LidConsumer exposes a builder and listener in order react to new states. LidConsumer is analogous to a nested LidListener and LidBuilder but reduces the amount of boilerplate needed. LidConsumer should only be used when it is necessary to both rebuild UI and execute other reactions to state changes in the stateNotifier.

LidConsumer takes a required LidWidgetBuilder and CubitWidgetListener and stateNotifier and an optional LidBuilderCondition, and LidListenerCondition.

LidConsumer<StateType>(
  stateNotifier: stateNotifier,
  listener: (context, state) {
    // do stuff here based on State Notifier's state
  },
  builder: (context, state) {
    // return widget here based on State Notifier's state
  }
)

An optional listenWhen and buildWhen can be implemented for more granular control over when listener and builder are called. The listenWhen and buildWhen will be invoked on each stateNotifier state change. They each take the previous state and current state and must return a bool which determines whether or not the builder and/or listener function will be invoked. The previous state will be initialized to the state of the stateNotifier when the LidConsumer is initialized. listenWhen is optional and if it isn't implemented, it will default to true. buildWhen is optional and if omitted, it will default true if previous state is different current state, otherwise is false, however the first time does not have an effect, always true.

CubitConsumer<CubitA, CubitAState>(
  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
  },
  buildWhen: (previous, current) {
    // return true/false to determine whether or not
    // to rebuild the widget with state
  },
  builder: (context, state) {
    // return widget here based on State Notifier's state
  }
)

Implementation

const LidConsumer({
  Key? key,
  required this.listener,
  required this.stateNotifier,
  required this.builder,
  this.listenWhen,
  this.buildWhen,
  this.animate = false,
  this.transitionBuilder = AnimatedSwitcher.defaultTransitionBuilder,
  this.duration = const Duration(milliseconds: 300),
}) : super(key: key);