5 4 月 2026, 周日
showDialog(
      context: context,
      barrierDismissible: false,//点击外部遮罩区域是否可以关闭dialog
      builder: (context) {
        return WillPopScope(
          onWillPop: () async => false,//关键代码
          child: Dialog(
            backgroundColor: Colors.transparent,
            insetPadding: EdgeInsets.zero,
            child: child,
          ),
        );
      },
    );

在Dialog的外面再嵌套一层WillPopScope,并将onWillPop设为false即可。

Avatar photo

sion932