我是Flutter的新手,我遇到了一个问题。
我用的是mobx。在我看来,我有一个按钮,在这个按钮里面,
我正在等待showDialog属性更改,以便显示对话框视图。但是,在onpress中,显示对话框不起作用。有没有其他方法可以做到这一点?
我的控制器
@observable
bool showDialog = false;
@action
Future callLoginService() async {
await Future.delayed(Duration(seconds: 6));
showDialog = true;
}视图
Observer(
builder: (_) {
return Center(
child: RaisedButton(
child: Text("TESTE"),
onPressed: () async {
controller.callLoginService();
if (controller.showDialog) {
final action = await InfoDialogView.showAlertDialog(
context, "Try again", 'Invalid user');
if (action == DialogAction.abort) {
controller.showDialog = false;
}
}
},
),
);
},
),发布于 2021-05-12 18:06:43
这是因为您的onPressed方法是异步的,但是您没有在controller.callLoginService()之前使用'await‘关键字。
Observer(
builder: (_) {
return Center(
child: RaisedButton(
child: Text("TESTE"),
onPressed: () async {
await controller.callLoginService(); //put await for calling asynchronous methods
if (controller.showDialog) {
final action = await InfoDialogView.showAlertDialog(
context, "Try again", 'Invalid user');
if (action == DialogAction.abort) {
controller.showDialog = false;
}
}
},
),
);
},
),https://stackoverflow.com/questions/63543179
复制相似问题