showAlertDialog static method
void
showAlertDialog({
- Widget? title,
- required Widget content,
- Widget? cancel,
- Widget? confirm,
- VoidCallback? onCancel,
- VoidCallback? onConfirm,
- List<
CupertinoDialogAction> ? actions, - bool barrierDismissible = true,
- bool isIOSStyle = true,
Implementation
static void showAlertDialog({
Widget? title,
required Widget content,
Widget? cancel,
Widget? confirm,
VoidCallback? onCancel,
VoidCallback? onConfirm,
List<CupertinoDialogAction>? actions,
bool barrierDismissible = true,
bool isIOSStyle = true,
}) {
Widget baseAlertDialog;
if (!isIOSStyle) {
baseAlertDialog = AlertDialog(
contentPadding: const EdgeInsets.all(0),
title: title ??
Center(
child: Text("温馨提示".tr),
),
titleTextStyle: Theme.of(Get.context!).textTheme.titleMedium,
titlePadding: const EdgeInsets.fromLTRB(16, 16, 16, 0),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(CommonStyle.roundedMd)),
),
content: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 20),
child: content,
),
Divider(
thickness: 0.5,
height: 0,
color: Get.isDarkMode ? Colors.white : Colors.black12,
),
SizedBox(
height: 46,
width: double.infinity,
child: Row(
children: [
Expanded(
child: InkWell(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
child: Container(
height: double.infinity,
alignment: Alignment.center,
clipBehavior: Clip.hardEdge,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(16)),
),
child: cancel ?? Text("取消".tr),
),
onTap: () =>
onCancel != null ? onCancel.call() : Get.back(),
),
),
VerticalDivider(
thickness: 0.5,
width: 0,
color: Get.isDarkMode ? Colors.white : Colors.black12,
),
Expanded(
child: InkWell(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
child: Container(
height: double.infinity,
alignment: Alignment.center,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(16)),
),
child: confirm ?? Text("确定".tr),
),
onTap: () => onConfirm?.call(),
),
),
],
),
),
],
),
);
} else {
baseAlertDialog = CupertinoAlertDialog(
title: title ??
Center(
child: Text("温馨提示".tr),
),
content: Padding(
padding: const EdgeInsets.only(top: 12),
child: content,
),
actions: actions ??
<CupertinoDialogAction>[
CupertinoDialogAction(
onPressed: () =>
onCancel != null ? onCancel.call() : Get.back(),
child: cancel ?? Text('取消'.tr),
),
CupertinoDialogAction(
onPressed: () => onConfirm?.call(),
child: confirm ?? Text('确定'.tr),
),
],
);
}
Get.dialog(
baseAlertDialog,
barrierDismissible: barrierDismissible,
);
}