showDialog 点击空白区域禁止弹窗关闭可以设置:barrierDismissible: false
禁止物理按键的返回键或者侧滑关闭可以使用 WillPopScope
组件,onWillPop 函数返回 false
。
showDialog<bool>(
context: context,
builder: (BuildContext context) {
return WillPopScope(child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
FocusManager.instance.primaryFocus?.unfocus();
},
child: Container(
margin: EdgeInsets.symmetric(
horizontal: 60.w, vertical: ScreenUtil().screenHeight / 4),
padding: EdgeInsets.symmetric(horizontal: 20.w),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(24.r),
),
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setter) {
return Text('test');
},
),
),
), onWillPop: ()async{
return false;
});
});