Issue
I want to split my BLOC into two BLOCs:
- the one who does preparing job
- the main one
Let’s call it PrepBloc and MainBloc. Is it reasonable way to put one inside another like this:
BlocProvider<PrepBloc>(
create: ......,
child: AppView()
)
class AppView extends StatelessWidget {
Widget build(BuildContext context) {
return BlocBuilder<PrepBloc, PrepState>(
builder: (context, state) {
if (state is ReadyState) {
return BlocProvider<MainBloc>(...);
}
else if (state is NotReadyState) {
return PrepPage();
}
}
);
}
}
I know there is MultiBloc thing but it seems to me a little sophisticated and producing a lots of code.
Solution
That is absolutley a correct way to do it!
You would use a MultiBlocProvider if the children need access to both blocs, but in your case that isn’t what you are after. I guess there is no point for PrepPage to have access to MainBloc.
Answered By – Robert Sandberg
Answer Checked By – David Marino (FlutterFixes Volunteer)