MultiBlocBuilder constructor
const
MultiBlocBuilder({})
MultiBlocBuilder handles building a widget by observing state of variouse Blocs
and should be used in combination with the flutter_bloc package.
Specify the bloc to observed via the blocs parameter.
The builder rebuilds each time a state change occurs and provides a context (BuildContext) and the states (BlocStates).
How to use:
final bloc1 = BlocProvider.of<MyBloc1>(context);
final bloc2 = BlocProvider.of<MyBloc2>(context);
final bloc3 = BlocProvider.of<MyBloc2>(context);
MultiBlocBuilder(
blocs: [bloc1, bloc2, bloc3],
builder: (context, states) {
final state1 = states.get<MyBloc1State>();
final state2 = states.get<MyBloc2State>();
final state3 = states.get<MyBloc3State>();
if (state1 is Loading || state2 is Loading || state3 is Loading) {
return Text("Loading");
} else {
return Text("SHow some content");
}
}
);
example 2 with getState for using same state type for multi bloc
MultiBlocBuilder(
blocs: bloc1, bloc2, bloc3,
builder: (context, states) {
final state1 = states.getState
if (state1 is Loading || state2 is Loading || state3 is Loading) {
return Text("Loading");
} else {
return Text("SHow some content");
}
} );
Implementation
const MultiBlocBuilder({
super.key,
required List<BlocBase> blocs,
required Widget Function(BuildContext, BlocStates) builder,
bool Function(BuildContext, BlocStates)? buildWhen,
}) :
_blocs = blocs,
_builder = builder,
_buildWhen =buildWhen;