Flutter alert dialog issue

97 views Asked by At

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,
      ),
    ]
);
1

There are 1 answers

5
For Stack On

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