Reputation: 17360
in one of my classes in application i want to pass BlocProvider
with class parameter, for example:
enum MenuItems{
dashboard,
tutorials,
logout
}
class DashboardItems {
MenuItems menuItem;
BlocProvider action;
DashboardItems(
{
@required this.menuItem,
@required this.action
}
);
}
in that with action
field i try to pass this method:
BlocProvider.of<MyEvent>(context).dispatch(MyEvent(event)))
such as:
DashboardItems(
menuItem: MenuItems.dashboard,
action: BlocProvider.of<FragmentBloc>(context).dispatch(FragmentEvent(fragmentHome))),
is any solution to pass and use that?
Upvotes: 2
Views: 962
Reputation: 16225
Looks like you are passing not a function but a result of the function.
DashboardItems(
menuItem: MenuItems.dashboard,
// pass function here:
action: () { BlocProvider.of<FragmentBloc>(context).dispatch(FragmentEvent(fragmentHome));}
class DashboardItems {
MenuItems menuItem;
Function action; //Change type from BlocProvider to Function.
DashboardItems(
{
@required this.menuItem,
@required this.action
}
);
}
Upvotes: 2