app_custom_dialog.dart 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import 'package:cs_resources/constants/color_constants.dart';
  2. import 'package:cs_resources/generated/assets.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  5. import 'package:get/get.dart';
  6. import 'package:widgets/ext/ex_widget.dart';
  7. import 'package:widgets/my_load_image.dart';
  8. import '../my_text_view.dart';
  9. import 'dart:ui';
  10. import 'package:flutter/cupertino.dart';
  11. import 'package:flutter/widgets.dart';
  12. import 'package:widgets/widget_export.dart';
  13. import '../no_shadow_scroll_behavior.dart';
  14. /*
  15. * 自定义的弹窗
  16. * 可自定义设置弹窗的宽度 默认宽度 MediaQuery.of(context).size.width * 0.65
  17. * 弹框内容自定义传入 messageBuilder
  18. */
  19. class AppCustomDialog extends StatelessWidget {
  20. String? title;
  21. double? titleSize;
  22. Color? titleColor;
  23. String message;
  24. double? dialogWidth;
  25. double? contentBoxMaxHeight;
  26. double? contentBoxMinHeight;
  27. Widget Function(BuildContext context)? messageBuilder;
  28. VoidCallback confirmAction;
  29. VoidCallback? cancelAction;
  30. bool isShowCancelBtn;
  31. bool isShowConfirmBtn = true;
  32. String? confirmTxt;
  33. String? cancelTxt;
  34. bool confirmAutoDismiss = true;
  35. AppCustomDialog({super.key,
  36. required this.message,
  37. required this.confirmAction,
  38. this.messageBuilder,
  39. this.title,
  40. this.titleSize = 18,
  41. this.titleColor = Colors.black,
  42. this.dialogWidth,
  43. this.contentBoxMaxHeight = 500,
  44. this.contentBoxMinHeight = 300,
  45. this.cancelAction,
  46. this.isShowCancelBtn = true,
  47. this.isShowConfirmBtn = true,
  48. this.confirmTxt,
  49. this.cancelTxt,
  50. this.confirmAutoDismiss = true,
  51. });
  52. @override
  53. Widget build(BuildContext context) {
  54. // Widget Function(BuildContext context)? _newMessageBuilder;
  55. return SizedBox(
  56. width: dialogWidth?? MediaQuery.of(context).size.width * 0.65,
  57. child: Column(
  58. crossAxisAlignment: CrossAxisAlignment.center,
  59. mainAxisAlignment: MainAxisAlignment.center,
  60. mainAxisSize: MainAxisSize.max,
  61. children: [
  62. //Title (如果使用 Container 为最外层容器则默认为 match_parent 的效果,除非我们限制宽度和最大高度最小高度)
  63. Container(
  64. width: double.infinity,
  65. height: 55,
  66. decoration: const BoxDecoration(
  67. color: Colors.white,
  68. borderRadius: BorderRadius.only(
  69. topRight: Radius.circular(8),
  70. topLeft: Radius.circular(8),
  71. ),
  72. ),
  73. child: Row(
  74. children: [
  75. const SizedBox(width: 45),
  76. MyTextView(
  77. title ?? "",
  78. fontSize: titleSize,
  79. textAlign: TextAlign.center,
  80. isFontMedium: true,
  81. textColor: titleColor?? Colors.black54,
  82. ).expanded(),
  83. const MyAssetImage(Assets.baseServiceDialogDeleteIcon,width: 25,height: 25.5,).onTap((){
  84. onCancel();
  85. })
  86. ]
  87. ),
  88. ),
  89. Container(
  90. width: double.infinity,
  91. decoration: const BoxDecoration(
  92. color: Colors.white,
  93. borderRadius: BorderRadius.only(
  94. bottomLeft: Radius.circular(15),
  95. bottomRight: Radius.circular(15),
  96. ),
  97. ),
  98. child:
  99. // 动态的 部分
  100. Column(
  101. children: [
  102. Scrollbar(
  103. child: ScrollConfiguration(
  104. behavior: NoShadowScrollBehavior(),
  105. child: Container(
  106. // width: double.infinity,
  107. // color: Colors.white,
  108. padding: const EdgeInsets.only(top: 15, bottom: 15),
  109. child: SingleChildScrollView(
  110. child: message.isNotEmpty?MyTextView(
  111. message,
  112. fontSize: 18,
  113. textColor: ColorConstants.black,
  114. isFontRegular: true,
  115. textAlign: TextAlign.center,
  116. paddingLeft: 30,
  117. paddingRight: 30,
  118. ): (messageBuilder != null ? messageBuilder!(context) : Container()),
  119. ),
  120. ),
  121. ),
  122. ).constrained(maxHeight: contentBoxMaxHeight?? 300),
  123. // Container(
  124. // margin: EdgeInsets.only(top: 25),
  125. // color: Color(0XFFCECECE),
  126. // height: 0.5,
  127. // ),
  128. const Divider(
  129. height: 0.5, // 设置 Divider 的高度
  130. thickness: 0.1, // 设置 Divider 的粗细
  131. color: Color(0XFFCECECE),
  132. ),
  133. // 底部按钮区域
  134. Container(
  135. padding: const EdgeInsets.only(top: 0, bottom: 0),
  136. decoration: const BoxDecoration(
  137. color: ColorConstants.white,
  138. borderRadius: BorderRadius.only(
  139. bottomLeft: Radius.circular(15),
  140. bottomRight: Radius.circular(15),
  141. ),
  142. ),
  143. child: Row(
  144. children: [
  145. Visibility(
  146. visible: isShowCancelBtn,
  147. child: Expanded(
  148. flex: 1,
  149. child: InkWell(
  150. onTap: () {
  151. onCancel();
  152. cancelAction?.call();
  153. },
  154. child: MyTextView(
  155. cancelTxt ?? 'Cancel'.tr,
  156. fontSize: 16,
  157. isFontMedium: true,
  158. paddingTop: 13,
  159. // marginRight: 15,
  160. paddingBottom: 13,
  161. textAlign: TextAlign.center,
  162. textColor: Color(0XFF0085C4),
  163. backgroundColor: Colors.white,
  164. cornerRadiusLeftTop: 0,
  165. cornerRadiusRightTop: 0,
  166. cornerRadiusLeftBottom: 7,
  167. cornerRadiusRightBottom: 0,
  168. ),
  169. )),
  170. ),
  171. // 分割线
  172. Container(
  173. width: 0.5,
  174. height: 40,
  175. color: Colors.grey.withOpacity(0.3),
  176. ),
  177. Visibility(
  178. visible: isShowConfirmBtn,
  179. child: Expanded(
  180. flex: 1,
  181. child: InkWell(
  182. onTap: () async {
  183. if(confirmAutoDismiss){
  184. onCancel();
  185. }
  186. confirmAction();
  187. },
  188. child: MyTextView(
  189. confirmTxt ?? 'Confirm'.tr,
  190. fontSize: 16,
  191. paddingTop: 13,
  192. paddingBottom: 13,
  193. isFontMedium: true,
  194. textAlign: TextAlign.center,
  195. textColor: Color(0XFF0085C4),
  196. backgroundColor: Colors.white,
  197. cornerRadiusLeftTop: 0,
  198. cornerRadiusRightTop: 0,
  199. cornerRadiusLeftBottom: 0,
  200. cornerRadiusRightBottom: 7,
  201. ),
  202. )),
  203. ),
  204. ],
  205. ).marginOnly(bottom: 0, top: 0),
  206. ),
  207. ],
  208. ),
  209. ),
  210. ],
  211. ).constrained(width: 300),
  212. );
  213. }
  214. //取消弹框
  215. void onCancel() async {
  216. SmartDialog.dismiss();
  217. }
  218. }