How to pass parameters to action in Flutter

久未见 提交于 2021-01-28 09:50:39

问题


I have this action

Future<void> signUpAction(Store<AppState> store) async {
  try {
    // ...
  } catch (e) {
    // ..
  }
}

And I dispatch it like this

store.dispatch(signUpAction);

Now, if I want to pass two paramters, how would I do that? Since there is already one parameter there.

I tried this

Future<void> signUpAction(Store<AppState> store, email, password) async {
  try {
    // ...
  } catch (e) {
    // ..
  }
}

but then on dispatching, if I do

store.dispatch(signUpAction("some@email.com", "somEPa55word!"));

it says the singUpAction expects 3 parameters, so I don't know very well how to pass only these two

Thank you


回答1:


The dispatch method expects a specific signature. If your method does not have exactly that signature, you can make an anonymous function on the fly that matches the signature.

In this case, since your method takes not only the store, but also the email and password:

store.dispatch((x) => signUpAction(x, "some@email.com", "somEPa55word!"));


来源:https://stackoverflow.com/questions/64529823/how-to-pass-parameters-to-action-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!