I have provided bloc in parent widget and trying to access that bloc instance in bottom sheet dialog. In bottom sheet dialog i have bloc builder which can not access the bloc instance.
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider<DevicePairBloc>(
create: (context) => DevicePairBloc(),
child: DeviceList(),
);
}
}
class DeviceList extends StatefulWidget {
@override
State<StatefulWidget> createState() => _DeviceListState();
}
class _DeviceListState extends State<DeviceList> {
void showData(BuildContext context) {
showModalBottomSheet(
context: context, builder: (context) => ReadingScreen());
}
@override
Widget build(BuildContext context) {
return ListView(
children: <Widget>[
RaisedButton(onPressed: () => showData(context),),
],
);
}
}
class ReadingScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder<DevicePairBloc, DevicePairState>(
builder: (context, state) {
return Text("20 mg");
},);
}
}