I have ScreenA with CubitA and StateA. From ScreenA, I am opening a modal bottom sheet and passing the CubitA through BlocProvider.value(). I also have a BlocBuilder inside the BottomSheet widget.
I can use CubitA correctly from inside the sheet (e.g: call a method inside when button pressed), but the state in the BottomSheet won't update after it changes.
Code
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (_) {
final cubit = Provider.of<CubitA>(context);
return BlocProvider.value(
value: cubit,
child: BottomSheetContent(),
);
},
);
BottomSheetWidget
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.fromLTRB(30, 20, 30, 20),
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
)),
child: SafeArea(
top: false,
child: BlocBuilder<OffersMapCubit, OffersMapState>(
bloc: context.watch<OffersMapCubit>(),
builder: (context, state) {
THIS IS ONLY CALLED ONCE AT STARTUP BUT NEVER AGAIN
return Content()...
);
}),
),
);
}
According to the documentation (https://pub.dev/packages/flutter_bloc), by using watch
or Provider.of()
, widgets in the subtree should listen for changes.
Is this expected behavior? Am I doing something wrong?
Any help is appreciated, thanks!