android - 如何在 FlatButton 单击时关闭 AlertDialog?

我有以下 AlertDialog

showDialog(
            context: context,
            child: new AlertDialog(
              title: const Text("Location disabled"),
              content: const Text(
                  """
Location is disabled on this device. Please enable it and try again.
                  """),
              actions: [
                new FlatButton(
                  child: const Text("Ok"),
                  onPressed: _dismissDialog,
                ),
              ],
            ),
        );

我怎样才能让 _dismissDialog() 关闭所说的 AlertDialog

最佳答案

Navigator.pop()应该做的伎俩。您还可以使用它来返回对话框的结果(如果它为用户提供了选择)

https://stackoverflow.com/questions/44159819/

相关文章:

dart - Flutter:如何解决错误导入包:http/http.dart

flutter - 检查 Flutter 应用上是否有可用的 Internet 连接

dart - 在没有动画的情况下替换 MaterialApp 中的初始路由?

dart - 无法更改 TextField 边框颜色

dart - 如何在 Flutter 中设置主屏幕的背景颜色?

dart - Flutter - 如何在 AppBar 不存在时设置状态栏颜色

flutter - 另一个异常被抛出 : type 'MyApp' is not a subtype

flutter - 如何在 Flutter Widget(Center Widget)的子属性中使用

android - 滑动列表项以获取更多选项(Flutter)

java - Flutter.io Android 许可证状态未知