I have a FloatingActionButton inside a widget tree which has a BlocProvider
from flutter_bloc. Something like this:
BlocProvider(
builder: (context) {
SomeBloc someBloc = SomeBloc();
someBloc.dispatch(SomeEvent());
return someBloc;
},
child: Scaffold(
body: ...
floatingActionButton: FloatingActionButton(
onPressed: _openFilterSchedule,
child: Icon(Icons.filter_list),
),
)
);
Which opens a modal bottom sheet:
void _openFilterSchedule() {
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return TheBottomSheet();
},
);
}
I am trying to access SomeBloc
using BlocProvider.of<SomeBloc>(context)
inside TheBottomSheet
but I get the following error:
BlocProvider.of() called with a context that does not contain a Bloc of type SomeBloc.
I have tried to use the solution described in https://mcmap.net/q/210481/-how-to-update-state-of-a-modalbottomsheet-in-flutter but only works for BottomSheet
and not ModalBottomSheet
.
Note: This is not restricted to BlocProvider
or flutter_bloc
. Any Provider from the provider package has the same behaviour.
How can I access BlocProvider.of<SomeBloc>(context)
inside the showModalBottomSheet
?
In case it's not possible to do that, how to adapt https://mcmap.net/q/210481/-how-to-update-state-of-a-modalbottomsheet-in-flutter solution to Modal Bottom Sheet?