import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'alert_dialog.dart'; /// 确认提示框 class DialogConfirm extends StatelessWidget { /// 确认信息 final String message; /// 标题,默认“提示” final String? title; /// 禁用取消按钮 final bool disableCancel; const DialogConfirm({ super.key, required this.message, this.disableCancel = false, this.title, }); /// 弹出确认框 /// /// [message] 确认信息 /// /// [title] 标题,默认“提示” /// /// [disableCancel] 禁用取消按钮 static Future show({ required String message, String? title, bool disableCancel = false, }) async { final result = await Get.dialog( DialogConfirm( message: message, title: title, disableCancel: disableCancel, ), barrierDismissible: false, ); return result == true; } @override Widget build(BuildContext context) { return VAlertDialog( title: title ?? "提示", width: 320, content: Column( // 自适应高度 mainAxisSize: MainAxisSize.min, children: [ Container( padding: const EdgeInsets.symmetric(horizontal: 24), alignment: Alignment.center, child: Row( children: [ // 自适应换行 Expanded( child: Text( message, style: const TextStyle(fontSize: 20), ), ), ], ), ) ], ), onConfirm: () { Get.back(result: true); }, showCancel: disableCancel == false, onCanceled: () { Get.back(result: false); }, ); } }