Describe the bug
I may be missing something here, but my understanding is that declaring a Bloc in a parent widget's context should make it available to the subt tree. It does not seem to be working for me. I get the error
BlocProvider.of() called with a context that does not contain a Bloc of type CreateFormBloc
Parent Class:
`class ScreenWrapper extends StatelessWidget {
ScreenWrapper({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocBuilder
builder: (context, state) {
if (state is LoadingState || state is InitialState || state is SavingState) {
return Center(child: CircularProgressIndicator());
}
if (state is LoadedState) {
return AScreen();
}
if (state is CreateRequestedState) {
return BlocProvider
create:(BuildContext context) =>
CreateFormBloc(repository: RepositoryProvider.of
child: CreateScreen(),
);
}
if (state is SearchState) {
return SearchScreen();
}
}
}
`
In the CreateScreen, using BlocProvider.of fails with the error. BlocProvider.of() called with a context that does not contain a Bloc of type CreateFormBloc
I'm not sure what I'm missing here.
Hi @franagu 馃憢
Thanks for opening an issue!
It looks like you're not accessing the repository correctly. You need to specify the type of repository when you perform the lookup RepositoryProvider.of<MyRepository>(context),
Also make sure you're providing the bloc type BlocProvider.of<CreateFormBloc>(context).
Let me know if that helps!
Thank you! Was missing the proper declaration of the Repo Provider, also nested the CreateScreen in another widget.
Most helpful comment
Thank you! Was missing the proper declaration of the Repo Provider, also nested the CreateScreen in another widget.