BlocBuilder<Bloc extends StateStreamable<State>, State> constructor

const BlocBuilder<Bloc extends StateStreamable<State>, State>({
  1. required BlocWidgetBuilder<State> builder,
  2. required Bloc bloc,
  3. BlocBuilderCondition<State>? buildWhen,
  4. Key? key,
})

BlocBuilder handles building a widget in response to new states. BlocBuilder is analogous to StreamBuilder but has simplified API to reduce the amount of boilerplate code needed as well as bloc-specific performance improvements. Please refer to BlocListener if you want to "do" anything in response to state changes such as navigation, showing a dialog, etc...

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

BlocBuilder<BlocA, BlocAState>(
  builder: (context, state) {
  // return widget here based on BlocA's state
  }
)

Only specify the bloc if you wish to provide a bloc that is otherwise not accessible via BlocProvider and the current BuildContext.

BlocBuilder<BlocA, BlocAState>(
  bloc: blocA,
  builder: (context, state) {
  // return widget here based on BlocA's state
  }
)

Implementation

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