什么是Modal的onClose等同于Dart / Flutter的Dialog?

时间:2018-12-11 00:50:00

标签: dart flutter

我试图在对话框关闭时(通过提交或在用户按下对话框外部时退出)刷新我的状态。我将如何捕捉呢?相当于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,
        ),
      ],
    );
  }

1 个答案:

答案 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();