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?
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
}
);
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加