showSysConfirm static method

Future<void> showSysConfirm({
  1. String title = 'Confirm',
  2. String message = 'Do you want to do it?',
  3. String cancelLabelText = 'Cancel',
  4. String okLabelText = 'OK',
  5. Function? onCancel,
  6. required Function onConfirm,
})

显示系统原生确认对话框

title 标题 message 内容 cancelLabelText 取消按钮文本 okLabelText OK按钮文本 onCancel 取消回调 onConfirm 确认回调(必填)

用法示例

PPAlert.showSysConfirm(
  title: "确定要删除?",
  onConfirm: () { print("删除!"); },
  onCancel: () { print("取消!"); },
);

Implementation

static Future<void> showSysConfirm({
  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;
  }
  isAlerted = true;
  final result = await showOkCancelAlertDialog(
    context: Get.context!,
    title: title,
    message: message,
    cancelLabel: cancelLabelText,
    okLabel: okLabelText,
    barrierDismissible: false,
    defaultType: OkCancelAlertDefaultType.cancel,
  );
  isAlerted = false;
  if (result == OkCancelResult.ok) {
    onConfirm();
  } else if (result == OkCancelResult.cancel) {
    if (onCancel != null) {
      onCancel();
    }
  }
}