【发布时间】:2019-01-08 17:54:14
【问题描述】:
我正在尝试使用 redux_thunk 但我从演示中真正不明白的是如何向该函数发送参数。我有一个文件 actions.dart 在哪里 拥有所有的行动。从我的组件中,我想向该操作分派一些参数,以便我向 API 发出请求。例如,我想使用用户名、密码登录而不将它们保存在状态
actions.dart
final ThunkAction<AppState> login = (Store<AppState> store) async {
await new Future.delayed(
new Duration(seconds: 3),
() => "Waiting complete",
);
store.dispatch(OtherAction(....));
};
component.dart
class LoginBtn extends StatelessWidget {
@override
Widget build(BuildContext context) {
return StoreConnector<AppState, Function>(
converter: (store) => (){
login(store);
},
builder: (context, callback) {
return RaisedButton(
highlightElevation: 20.0,
child: Text('Login', style: TextStyle(color: Colors.white)),
color: Color(0xFF0f7186),
onPressed: () {
callback();
});
});
}
}
谁能帮我做一些快速修复或演示。谢谢!
这样的?
class MyAction {
String gender;
MyAction(
{this.gender});
ThunkAction<AppState> getDate() {
return (Store<AppState> store) async {...};
}
}
【问题讨论】:
-
也许这个答案会帮助其他人stackoverflow.com/a/64533014/3808307