import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:hgdj/assets_tool/app_colors.dart'; import 'package:hgdj/hj_utils/screen.dart'; import 'package:hgdj/tools_base/widget/common_dialog.dart'; /// 全站统一的提示/确认弹窗:标题 + 分割线 + 正文 + 副文案 + 灰「取消」红「确定」双按钮。 /// 壳走 [CommonDialog],业务结果一律用返回值传(点确定=true),别在弹窗里塞跳转逻辑。 /// 统一走 [show],别自己套 Get.dialog——barrierDismissible 要同时给到两层才生效。 class CommonAlert extends StatelessWidget { final String title; final String? content; //正文,16/半透明白 final String? subContent; //副文案,接在正文下方 final bool showDivider; //标题下的分割线 final bool showCancel; //false = 只有一个确定按钮 final String cancelText; final String confirmText; final bool barrierDismissible; //false = 只能点按钮,见 CommonDialog 同名参数 const CommonAlert({ super.key, this.title = '温馨提示', this.content, this.subContent, this.showDivider = true, this.showCancel = true, this.cancelText = '取消', this.confirmText = '确定', this.barrierDismissible = true, }); /// 弹出并等待结果:true = 点了确定,点取消/遮罩/返回键都是 false。 /// [barrierDismissible] 传 false 则必须点按钮才能关(权限、强制重试这类场景) static Future show({ String title = '温馨提示', String? content, String? subContent, bool showDivider = true, bool showCancel = true, String cancelText = '取消', String confirmText = '确定', bool barrierDismissible = true, }) async { final res = await Get.dialog( CommonAlert( title: title, content: content, subContent: subContent, showDivider: showDivider, showCancel: showCancel, cancelText: cancelText, confirmText: confirmText, barrierDismissible: barrierDismissible, ), barrierDismissible: barrierDismissible, ); return res ?? false; } @override Widget build(BuildContext context) { return CommonDialog( //点正文不关:结果只认按钮,误触关掉会被当成「取消」 canTapClose: false, barrierDismissible: barrierDismissible, child: Column( mainAxisSize: MainAxisSize.min, children: [ Text( title, style: TextStyle( color: Colors.white.withValues(alpha: .9), fontSize: 20, fontWeight: FontWeight.w600), ), if (showDivider) ...[ 12.sizeBoxH, 0.5.line, ], if (content?.isNotEmpty == true) ...[ 12.sizeBoxH, Text( content!, textAlign: TextAlign.center, style: TextStyle( color: Colors.white.withValues(alpha: .5), fontSize: 16, fontWeight: FontWeight.w500), ), ], if (subContent?.isNotEmpty == true) ...[ 20.sizeBoxH, Padding( padding: const EdgeInsets.symmetric(horizontal: 16), child: Text( subContent!, textAlign: TextAlign.center, style: TextStyle( color: Colors.white.withValues(alpha: .5), fontSize: 16), ), ), ], 31.sizeBoxH, SizedBox( height: 44, child: Row( children: [ if (showCancel) ...[ InkWell( enableFeedback: false, onTap: () => Get.back(result: false), child: Container( width: 112, alignment: Alignment.center, decoration: BoxDecoration( color: Colors.white.withValues(alpha: .1), borderRadius: BorderRadius.circular(3), ), child: Text( cancelText, style: const TextStyle( color: Color(0xff989898), fontSize: 16, fontWeight: FontWeight.w500), ), ), ), 12.sizeBoxW, ], Expanded( child: InkWell( enableFeedback: false, onTap: () => Get.back(result: true), child: Container( alignment: Alignment.center, decoration: BoxDecoration( color: AppColors.actionRed, borderRadius: BorderRadius.circular(3), ), child: Text( confirmText, style: const TextStyle( color: Colors.white, fontSize: 16, fontWeight: FontWeight.w500), ), ), ), ), ], ), ), ], ), ); } }