buildWhen property

BlocBuilderCondition<Connection>? buildWhen

An optional buildWhen can be implemented for more granular control over how often BlocBuilder rebuilds. buildWhen should only be used for performance optimizations as it provides no security about the state passed to the builder function. buildWhen will be invoked on each bloc state change. buildWhen takes the previous state and current state and must return a bool which determines whether or not the builder function will be invoked. The previous state will be initialized to the state of the bloc when the BlocBuilder is initialized. buildWhen is optional and if omitted, it will default to true.

BlocBuilder<BlocA, BlocAState>(
  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


final BlocBuilderCondition<S>? buildWhen;