Flutter警报对话框问题

lhcgjxsq  于 2023-06-24  发布在  Flutter
关注(0)|答案(1)|浏览(133)

警报对话框弹出未关闭。在以前,这个代码是工作,现在它不工作?当我点击取消或确认按钮后台导航工作但警报不能关闭前台是什么原因造成的问题?

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

58wvjzkj1#

您可以根据需要使用此代码。很完美。

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

相关问题