我试图在对话框关闭时(通过提交或在用户按下对话框外部时退出)刷新我的状态。我将如何捕捉呢?相当于JS / React的模态onClose。
showDialog(
context: this.context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Add a custom word'),
content: _renderForm(),
actions: <Widget>[
FlatButton(
child: Text('ADD'),
onPressed: () => (_textController.text.isNotEmpty) ? _addNewPair() : null,
),
],
);
}
答案 0 :(得分:1)
您可以在await
之前添加showDialog
关键字:
yourMethod () async {
await showDialog(
context: this.context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Add a custom word'),
content: _renderForm(),
actions: <Widget>[
FlatButton(
child: Text('ADD'),
onPressed: () => (_textController.text.isNotEmpty) ? _addNewPair() : null,
),
],
);
}
//here you can continue because your dialog was closed
print("after my dialog was closed");
}
如果您要关闭对话框,请使用以下命令:
Navigator.of(context).pop();