123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- import 'package:cs_resources/constants/color_constants.dart';
- import 'package:cs_resources/generated/assets.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
- import 'package:get/get.dart';
- import 'package:widgets/ext/ex_widget.dart';
- import 'package:widgets/my_load_image.dart';
- import '../my_text_view.dart';
- import 'dart:ui';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/widgets.dart';
- import 'package:widgets/widget_export.dart';
- import '../no_shadow_scroll_behavior.dart';
- /*
- * 自定义的弹窗
- * 可自定义设置弹窗的宽度 默认宽度 MediaQuery.of(context).size.width * 0.65
- * 弹框内容自定义传入 messageBuilder
- */
- class AppCustomDialog extends StatelessWidget {
- String? title;
- double? titleSize;
- Color? titleColor;
- String message;
- double? dialogWidth;
- double? contentBoxMaxHeight;
- double? contentBoxMinHeight;
- Widget Function(BuildContext context)? messageBuilder;
- VoidCallback confirmAction;
- VoidCallback? cancelAction;
- bool isShowCancelBtn;
- bool isShowConfirmBtn = true;
- String? confirmTxt;
- String? cancelTxt;
- bool confirmAutoDismiss = true;
- AppCustomDialog({super.key,
- required this.message,
- required this.confirmAction,
- this.messageBuilder,
- this.title,
- this.titleSize = 18,
- this.titleColor = Colors.black,
- this.dialogWidth,
- this.contentBoxMaxHeight = 500,
- this.contentBoxMinHeight = 300,
- this.cancelAction,
- this.isShowCancelBtn = true,
- this.isShowConfirmBtn = true,
- this.confirmTxt,
- this.cancelTxt,
- this.confirmAutoDismiss = true,
- });
- @override
- Widget build(BuildContext context) {
- // Widget Function(BuildContext context)? _newMessageBuilder;
- return SizedBox(
- width: dialogWidth?? MediaQuery.of(context).size.width * 0.65,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- mainAxisSize: MainAxisSize.max,
- children: [
- //Title (如果使用 Container 为最外层容器则默认为 match_parent 的效果,除非我们限制宽度和最大高度最小高度)
- Container(
- width: double.infinity,
- height: 55,
- decoration: const BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.only(
- topRight: Radius.circular(8),
- topLeft: Radius.circular(8),
- ),
- ),
- child: Row(
- children: [
- const SizedBox(width: 45),
- MyTextView(
- title ?? "",
- fontSize: titleSize,
- textAlign: TextAlign.center,
- isFontMedium: true,
- textColor: titleColor?? Colors.black54,
- ).expanded(),
- const MyAssetImage(Assets.baseServiceDialogDeleteIcon,width: 25,height: 25.5,).onTap((){
- onCancel();
- })
- ]
- ),
- ),
- Container(
- width: double.infinity,
- decoration: const BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.only(
- bottomLeft: Radius.circular(15),
- bottomRight: Radius.circular(15),
- ),
- ),
- child:
- // 动态的 部分
- Column(
- children: [
- Scrollbar(
- child: ScrollConfiguration(
- behavior: NoShadowScrollBehavior(),
- child: Container(
- // width: double.infinity,
- // color: Colors.white,
- padding: const EdgeInsets.only(top: 15, bottom: 15),
- child: SingleChildScrollView(
- child: message.isNotEmpty?MyTextView(
- message,
- fontSize: 18,
- textColor: ColorConstants.black,
- isFontRegular: true,
- textAlign: TextAlign.center,
- paddingLeft: 30,
- paddingRight: 30,
- ): (messageBuilder != null ? messageBuilder!(context) : Container()),
- ),
- ),
- ),
- ).constrained(maxHeight: contentBoxMaxHeight?? 300),
- // Container(
- // margin: EdgeInsets.only(top: 25),
- // color: Color(0XFFCECECE),
- // height: 0.5,
- // ),
- const Divider(
- height: 0.5, // 设置 Divider 的高度
- thickness: 0.1, // 设置 Divider 的粗细
- color: Color(0XFFCECECE),
- ),
- // 底部按钮区域
- Container(
- padding: const EdgeInsets.only(top: 0, bottom: 0),
- decoration: const BoxDecoration(
- color: ColorConstants.white,
- borderRadius: BorderRadius.only(
- bottomLeft: Radius.circular(15),
- bottomRight: Radius.circular(15),
- ),
- ),
- child: Row(
- children: [
- Visibility(
- visible: isShowCancelBtn,
- child: Expanded(
- flex: 1,
- child: InkWell(
- onTap: () {
- onCancel();
- cancelAction?.call();
- },
- child: MyTextView(
- cancelTxt ?? 'Cancel'.tr,
- fontSize: 16,
- isFontMedium: true,
- paddingTop: 13,
- // marginRight: 15,
- paddingBottom: 13,
- textAlign: TextAlign.center,
- textColor: Color(0XFF0085C4),
- backgroundColor: Colors.white,
- cornerRadiusLeftTop: 0,
- cornerRadiusRightTop: 0,
- cornerRadiusLeftBottom: 7,
- cornerRadiusRightBottom: 0,
- ),
- )),
- ),
- // 分割线
- Container(
- width: 0.5,
- height: 40,
- color: Colors.grey.withOpacity(0.3),
- ),
- Visibility(
- visible: isShowConfirmBtn,
- child: Expanded(
- flex: 1,
- child: InkWell(
- onTap: () async {
- if(confirmAutoDismiss){
- onCancel();
- }
- confirmAction();
- },
- child: MyTextView(
- confirmTxt ?? 'Confirm'.tr,
- fontSize: 16,
- paddingTop: 13,
- paddingBottom: 13,
- isFontMedium: true,
- textAlign: TextAlign.center,
- textColor: Color(0XFF0085C4),
- backgroundColor: Colors.white,
- cornerRadiusLeftTop: 0,
- cornerRadiusRightTop: 0,
- cornerRadiusLeftBottom: 0,
- cornerRadiusRightBottom: 7,
- ),
- )),
- ),
- ],
- ).marginOnly(bottom: 0, top: 0),
- ),
- ],
- ),
- ),
- ],
- ).constrained(width: 300),
- );
- }
- //取消弹框
- void onCancel() async {
- SmartDialog.dismiss();
- }
- }
|