0

Alert dialog pop not closing. In previously this code is worked as now its not working? when i clicked the cancel or confirm button background navigation is worked but alert cannot close foreground what cause the problem?

Dialogs.materialDialog(
    msg: 'Delete cart item ?',
    title: "Mojarto",
    color: Colors.white,
      barrierDismissible: true,
    context: context,
    actions: [
      IconsOutlineButton(
        onPressed: () {
          Navigator.of(context).pop();
        },
        text: 'Cancel',
        textStyle: TextStyle(color: Colors.grey),
        iconColor: Colors.grey,
      ),
      IconsButton(
        onPressed: () {
            Navigator.of(context)
              .pop();
          _apiResponse
              .removeCart(
                  getCartViewModel[
                          index]
                      .id
                      .toString())
              .then((value) {
            if (value) {
              Navigator.pop(context);
              clearAllFilters();
              Navigator.push(context,
                  PageTransition( type: PageTransitionType.fade,
                    child: CartPage(widget.lotno),
                  ));
            }
          });
        },
        text: "Delete",
        color: Colors.red,
        textStyle: TextStyle(
            color:
                Colors.white),
        iconColor: Colors.white,
      ),
    ]
);
Jan Schultke
  • 17,446
  • 6
  • 47
  • 96

1 Answers1

0

You can use this code according to your need. It works perfect.

 Future<bool?> showDeleteDialog(BuildContext context) async {
    return await showDialog<bool>(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: const Text('Delete Account'),
          content: const Text('Are you sure you want to delete your account?'),
          actions: <Widget>[
            TextButton(
              child: const Text('Cancel'),
              onPressed: () {
                Navigator.of(context).pop(false);
              },
            ),
            TextButton(
              child: const Text(
                'Delete',
                style: TextStyle(color: Colors.red),
              ),
              onPressed: () {
                Navigator.of(context).pop(true);
              },
            ),
          ],
        );
      },
    );
  }
For Stack
  • 165
  • 15
  • why we use true or false in pop function – Ezhilarasan S Jun 23 '23 at 08:35
  • the `true` or `false` value is used in the pop function to indicate the result of the dialog. – For Stack Jun 25 '23 at 09:48
  • if I am using above code its working fine but once I click delete button alert closed but that particular page font styles not working. I show without font style – Ezhilarasan S Jun 26 '23 at 04:50
  • I can't tell you what the issue is now until you share updated code. Maybe you are missing something in your code. – For Stack Jun 26 '23 at 05:23
  • TextButton( child: const Text( 'Delete', style: TextStyle(color: Colors.red), ), onPressed: () { Navigator.of(context).pop(true); Navigator.push( context, PageTransition( type: PageTransitionType.fade, child: CartPage(widget.lotno), )); }, ), – Ezhilarasan S Jun 26 '23 at 06:04