【发布时间】:2021-02-04 12:21:11
【问题描述】:
这可能是一个愚蠢的问题,但我不知道如何弄清楚: 如何防止 CupertinoActionSheet/showCupertinoModalPopup 在您点击外部时关闭?
我为 gps 搜索(半径)创建了一个选择器列表,我必须防止用户在未选择任何值的情况下将其关闭。
_showDialog2() {
Platform.isAndroid
? showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return RadiusSelectorDialog();
})
: showCupertinoModalPopup(
context: context,
builder: (context) {
return CupertinoRadiusSelectorPopup();
}).then((value) => print(value));
}
在 Android 对话框的情况下,将 barierDismissable 设置为 false 就足够了。但是在 showCupertinoModalPopup 中这种属性是不存在的。我试过用 Absorb 指针包裹它,但是当你在外面点击时它仍然可以被关闭。
我的行动表
class _CupertinoRadiusSelectorPopupState
extends State<CupertinoRadiusSelectorPopup> {
Color color = Colors.grey[900];
double fontSize = 15.0;
@override
Widget build(BuildContext context) {
return CupertinoActionSheet(
title: Text('Search in range:',
style: TextStyle(
color: Colors.black,
fontSize: 18,
)),
message: Text('Search for points in selected range'),
actions: [
CupertinoActionSheetAction(
onPressed: () => onPressed("10"),
child: Text('10 km',
style: TextStyle(color: color, fontSize: fontSize))),
CupertinoActionSheetAction(
onPressed: () => onPressed("25"),
child: Text('25 km',
style: TextStyle(color: color, fontSize: fontSize))),
CupertinoActionSheetAction(
onPressed: () => onPressed("50"),
child: Text('50 km',
style: TextStyle(color: color, fontSize: fontSize))),
CupertinoActionSheetAction(
onPressed: () => onPressed("100"),
child: Text('100 km',
style: TextStyle(color: color, fontSize: fontSize))),
],
);
}
onPressed(String value) {
print(value);
Navigator.pop(context, value);
}
}
【问题讨论】: