passing BlocProvider with class parameters

DolDurma

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?

Kherel

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]

編集
0

コメントを追加

0

関連記事

分類Dev

How do you deserialize derived class while passing parameters to base class

分類Dev

Passing parameters to middleware in Laravel

分類Dev

Passing parameters to a custom URI

分類Dev

Passing parameters to AngularJS $timeout

分類Dev

Passing parameters to a custom URI

分類Dev

Passing LINQ expressions as parameters

分類Dev

Passing parameters to jest function

分類Dev

Passing parameters to a OPENQUERY

分類Dev

Passing parameters to a react component

分類Dev

Error with passing parameters

分類Dev

Maple passing parameters by reference

分類Dev

Iframe not passing url parameters

分類Dev

Golang: Passing structs as parameters of a function

分類Dev

Passing additional parameters to MapStruct mapper

分類Dev

Passing parameters in rmarkdown to the text or headings

分類Dev

Passing parameters to scalameta paradise macro

分類Dev

Angular 6 passing in parameters into URL

分類Dev

Passing parameters in java script function ?

分類Dev

Passing iterators to class functions

分類Dev

Passing class props to mapStateToProps

分類Dev

Indirectly changing class parameters

分類Dev

name of class with generic parameters?

分類Dev

Passing case class into function arguments

分類Dev

Passing interface as a parameter to the Class constructor

分類Dev

Passing String Array to A Robotium Class

分類Dev

Passing argument to a Perl class subroutin

分類Dev

Passing list of enum values as HTTP query parameters

分類Dev

Passing parameters through Ajax success function

分類Dev

Passing list of enum values as HTTP query parameters