12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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;
- /// 弹窗宽度
- final double? width;
- const DialogConfirm({
- super.key,
- required this.message,
- this.disableCancel = false,
- this.title,
- this.width,
- });
- /// 弹出确认框
- ///
- /// [message] 确认信息
- ///
- /// [title] 标题,默认“提示”
- ///
- /// [disableCancel] 禁用取消按钮
- ///
- /// [width] 自定义弹框宽度
- static Future<bool> show({
- required String message,
- String? title,
- bool disableCancel = false,
- double? width,
- }) async {
- final result = await Get.dialog(
- DialogConfirm(
- message: message,
- title: title,
- disableCancel: disableCancel,
- width: width,
- ),
- barrierDismissible: false,
- );
- return result == true;
- }
- @override
- Widget build(BuildContext context) {
- return VAlertDialog(
- title: title ?? "提示",
- width: 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: () {},
- );
- }
- }
|