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即可。
THE END