1

我有这个动作

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

我像这样发送它

store.dispatch(signUpAction);

现在,如果我想传递两个参数,我该怎么做?因为那里已经有一个参数。

我试过这个

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

但是然后在调度时,如果我这样做

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

它说 singUpAction 需要 3 个参数,所以我不太清楚如何只传递这两个

谢谢

4

1 回答 1

1

dispatch 方法需要一个特定的签名。如果您的方法不完全具有该签名,您可以动态创建一个与签名匹配的匿名函数。

在这种情况下,由于您的方法不仅需要商店,还需要电子邮件和密码:

store.dispatch((x) => signUpAction(x, "some@email.com", "somEPa55word!"));
于 2020-10-26T07:34:14.603 回答