RxMultiBlocProvider constructor
const
RxMultiBlocProvider({
- Key? key,
- required List<
RxBlocProvider< providers,RxBlocTypeBase> > - required Widget child,
Merges multiple BlocProvider
widgets into one widget tree.
RxMultiBlocProvider improves the readability and eliminates the need to nest multiple RxBlocProviders.
By using RxMultiBlocProvider we can go from:
RxBlocProvider<BlocA>(
create: (BuildContext context) => BlocA(),
child: RxBlocProvider<BlocB>(
create: (BuildContext context) => BlocB(),
child: RxBlocProvider<BlocC>(
create: (BuildContext context) => BlocC(),
child: ChildA(),
)
)
)
to:
RxMultiBlocProvider(
providers: [
RxBlocProvider<BlocA>(
create: (BuildContext context) => BlocA(),
),
RxBlocProvider<BlocB>(
create: (BuildContext context) => BlocB(),
),
RxBlocProvider<BlocC>(
create: (BuildContext context) => BlocC(),
),
],
child: ChildA(),
)
RxMultiBlocProvider converts the RxBlocProvider list into a tree of nested RxBlocProvider widgets. As a result, the only advantage of using RxMultiBlocProvider is improved readability due to the reduction in nesting and boilerplate.
Implementation
const RxMultiBlocProvider({
Key? key,
required this.providers,
required this.child,
}) : super(key: key);