关闭 Cupertino 对话操作 Flutter

Dismissing a Cupertino dialogue action Flutter

在使用解释的方法取消显示的 Cupertino 警报对话操作时,我的整个屏幕都被弹出,并且警报对话保留在屏幕上。这是我的代码。

if (deviceList.isEmpty){

      var alert = new CupertinoAlertDialog(
        title: new Text("Alert"),
        content: new Text("There was an error signing in. Please try again."),
        actions: <Widget>[
          new CupertinoDialogAction(
              child: const Text('Discard'),
              isDestructiveAction: true,
              onPressed: () { Navigator.pop(context, 'Discard'); }
          ),
          new CupertinoDialogAction(
              child: const Text('Cancel'),
              isDefaultAction: true,
              onPressed: () { Navigator.pop(context, 'Cancel'); }
          ),
        ],
      );
      showDialog(context: context, child: alert);
    }

我这样做有什么问题吗?我找不到任何其他解决方案来关闭警报对话框。请帮忙。

在这种情况下,您需要指定rootNavigatorof()

Navigator.of(context, rootNavigator: true).pop("Discard");

勾选the implementation proposed in the documentation