IsolateBlocConsumer<B extends IsolateBlocBase<Object?, S>, S> constructor

const IsolateBlocConsumer<B extends IsolateBlocBase<Object?, S>, S>({
  1. Key? key,
  2. required BlocWidgetBuilder<S> builder,
  3. required BlocWidgetListener<S> listener,
  4. IsolateBlocWrapper? bloc,
  5. BlocBuilderCondition<S>? buildWhen,
  6. IsolateBlocListenerCondition<S>? listenWhen,
})

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

IsolateBlocConsumer takes a required BlocWidgetBuilder and BlocWidgetListener and an optional bloc, BlocBuilderCondition, and BlocListenerCondition.

If the bloc parameter is omitted, IsolateBlocConsumer will automatically perform a lookup using IsolateBlocProvider and the current BuildContext.

IsolateBlocConsumer<BlocA, BlocAState>(
  listener: (context, state) {
    // do stuff here based on BlocA's state
  },
  builder: (context, state) {
    // return widget here based on BlocA'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 bloc 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 bloc when the IsolateBlocConsumer is initialized. listenWhen and buildWhen are optional and if they aren't implemented, they will default to true.

IsolateBlocConsumer<BlocA, BlocAState>(
  listenWhen: (previous, current) {
    // return true/false to determine whether or not
    // to invoke listener with state
  },
  listener: (context, state) {
    // do stuff here based on BlocA'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 BlocA's state
  }
)

Implementation

const IsolateBlocConsumer({
  Key? key,
  required this.builder,
  required this.listener,
  this.bloc,
  this.buildWhen,
  this.listenWhen,
}) : super(key: key);