Reputation: 115
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider<TripDetailBloc>(create: (BuildContext context) => TripDetailBloc()),
BlocProvider<PopUpBloc>(create: (BuildContext context) => PopUpBloc()),
],
child: Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
BlocProvider.of<TripDetailBloc>(context).add(AddTripDetailPannelEvent());
},
),
appBar: appbar(),
body: pannel(),
)
);
}
The following assertion was thrown while handling a gesture:
<TripDetailBloc>()
.Upvotes: 3
Views: 1083
Reputation: 621
Change your code to this:
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider<TripDetailBloc>(create: (BuildContext context) => TripDetailBloc()),
BlocProvider<PopUpBloc>(create: (BuildContext context) => PopUpBloc()),
],
child: Builder(
builder: (context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
BlocProvider.of<TripDetailBloc>(context).add(AddTripDetailPannelEvent());
},
),
appBar: appbar(),
body: pannel(),
);
}
)
);
}
If you look closely, I have rapped your Scaffold into a widget builder.
Upvotes: 4
Reputation: 5601
Wrap your scaffold in a builder widget and use that context. The context the .of(context) is using is the same of the method build(BuildContext context), that's why it doesn't find it
Upvotes: 0