Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dismissing a Cupertino dialogue action Flutter

While dismissing a presented Cupertino alert dialogue action using the explained method my entire screen gets popped of and the alert dialogue stays on the screen. This is my code.

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);
    }

Is there anything wrong in what I am doing? I cant find any other solution to dismiss the alert dialogue. Please help.

like image 585
Chaythanya Nair Avatar asked Apr 02 '18 12:04

Chaythanya Nair


People also ask

How do you dismiss a dialog flutter?

If you don't want to return any result after showDialog is closed, you can use it. Navigator. pop(context);

How do I stop dialog close on click outside flutter?

To prevent the dialog from closing on outside barrier touch, you have to set barrierDismissible to false. It is true by default.

How do I close Showcupertinomodalpopup?

Background the app on the phone, e.g. by going back to the home screen. Press the Stop button in Xcode to terminate the app while running in the background. Open the app again on the phone (not via Xcode). It will restart and restore its state.


1 Answers

In this case, you need to specify the rootNavigator to of() :

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

Check the implementation proposed in the documentation

like image 57
Serge B. Avatar answered Sep 28 '22 23:09

Serge B.