如何在Flutter中将参数传递给动作 [英] How to pass parameters to action in Flutter
本文介绍了如何在Flutter中将参数传递给动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个动作
Future<void> signUpAction(Store<AppState> store) async {
try {
// ...
} catch (e) {
// ..
}
}
我是这样派发的
store.dispatch(signUpAction);
现在,如果我想传递两个参数,我该怎么做?由于那里已经有一个参数.
Now, if I want to pass two paramters, how would I do that? Since there is already one parameter there.
我尝试过
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!"));
它说singUpAction需要3个参数,所以我不太清楚如何仅传递这两个参数
it says the singUpAction expects 3 parameters, so I don't know very well how to pass only these two
谢谢
推荐答案
dispatch方法需要特定的签名.如果您的方法没有确切的签名,则可以创建匿名函数即时匹配签名.
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!"));
这篇关于如何在Flutter中将参数传递给动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文