showSysConfirm static method
显示系统原生确认对话框
title 标题
message 内容
cancelLabelText 取消按钮文本
okLabelText OK按钮文本
onCancel 取消回调
onConfirm 确认回调(必填)
用法示例
PPAlert.showSysConfirm(
title: "确定要删除?",
onConfirm: () { print("删除!"); },
onCancel: () { print("取消!"); },
);
Implementation
static Future<void> showSysConfirm({
BuildContext? context,
String title = 'Confirm',
String message = 'Do you want to do it?',
String cancelLabelText = 'Cancel',
String okLabelText = 'OK',
Function? onCancel,
required Function onConfirm,
}) async {
if (isAlerted) {
return;
}
final dialogContext = _resolveDialogContext(context);
if (dialogContext == null) return;
isAlerted = true;
try {
if (!dialogContext.mounted) return;
final result = GetPlatform.isAndroid
? await _showAndroidAlert(
context: dialogContext,
title: title,
message: message,
cancelLabelText: cancelLabelText,
okLabelText: okLabelText,
barrierDismissible: false,
)
: await showOkCancelAlertDialog(
context: dialogContext,
title: title,
message: message,
cancelLabel: cancelLabelText,
okLabel: okLabelText,
barrierDismissible: false,
defaultType: OkCancelAlertDefaultType.cancel,
);
if (result == OkCancelResult.ok) {
onConfirm();
} else if (result == OkCancelResult.cancel) {
if (onCancel != null) {
onCancel();
}
}
} finally {
isAlerted = false;
}
}