社区成员thejitenpatel改进了CupertinoAlertDialog在黑暗模式下的原生保真度,如下图所示:
旧版本的展示效果如下:
使用案例如下:
void _showAlertDialog(BuildContext context) {
showCupertinoDialog<void>(
context: context,
builder:
(BuildContext context) => CupertinoAlertDialog(
title: const Text('Alert'),
content: const Text('Proceed with destructive action?'),
actions: <CupertinoDialogAction>[
CupertinoDialogAction(
//该参数用于指定该按钮是否为默认操作按钮。
// 如果设置为 true,按钮上的文本会以加粗样式显示,
// 以突出显示该操作是对话框的默认选择。默认值为 false。
isDefaultAction: true,
//可选的回调函数,当用户点击该 CupertinoDialogAction 按钮时会触发此函数。
// 如果该参数为 null,按钮将变为不可用状态。
onPressed: () {
Navigator.pop(context);
},
child: const Text('No'),
),
CupertinoDialogAction(
isDestructiveAction: true,
onPressed: () {
Navigator.pop(context);
},
child: const Text('Yes'),
),
],
),
);
}
- isDestructiveAction:该参数用于指定该按钮是否为具有破坏性的操作按钮,例如删除操作。如果设置为 true,按钮上的文本会以红色样式显示,以提醒用户该操作可能会带来不可恢复的后果。默认值为 false。
- isDefaultAction:该参数用于指定该按钮是否为默认操作按钮。如果设置为 true,按钮上的文本会以加粗样式显示,以突出显示该操作是对话框的默认选择。默认值为 false。
【公众号 biglead】