app_custom_dialog.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import 'package:cs_resources/generated/assets.dart';
  2. import 'package:cs_resources/generated/l10n.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_smart_dialog/flutter_smart_dialog.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. String message;
  22. double? dialogWidth;
  23. double? contentBoxMaxHeight;
  24. double? contentBoxMinHeight;
  25. Widget Function(BuildContext context)? messageBuilder;
  26. VoidCallback confirmAction;
  27. VoidCallback? cancelAction;
  28. bool isShowCancelBtn;
  29. String? confirmTxt;
  30. String? cancelTxt;
  31. AppCustomDialog({super.key,
  32. required this.message,
  33. required this.confirmAction,
  34. this.messageBuilder,
  35. this.title,
  36. this.dialogWidth,
  37. this.contentBoxMaxHeight = 500,
  38. this.contentBoxMinHeight = 300,
  39. this.cancelAction,
  40. this.isShowCancelBtn = true,
  41. this.confirmTxt,
  42. this.cancelTxt,
  43. });
  44. @override
  45. Widget build(BuildContext context) {
  46. //使用一个 Column 为最外层容器,可以方便的视线 wrap_content 的效果
  47. return SizedBox(
  48. width: dialogWidth?? MediaQuery.of(context).size.width * 0.65,
  49. child: Column(
  50. crossAxisAlignment: CrossAxisAlignment.center,
  51. mainAxisAlignment: MainAxisAlignment.center,
  52. mainAxisSize: MainAxisSize.max,
  53. children: [
  54. //Title (如果使用 Container 为最外层容器则默认为 match_parent 的效果,除非我们限制宽度和最大高度最小高度)
  55. Container(
  56. width: double.infinity,
  57. height: 55,
  58. decoration: BoxDecoration(
  59. color: context.appColors.btnBgDefault,
  60. borderRadius: const BorderRadius.only(
  61. topRight: Radius.circular(15),
  62. topLeft: Radius.circular(15),
  63. ),
  64. ),
  65. child: Row(
  66. children: [
  67. const SizedBox(width: 45),
  68. MyTextView(
  69. title ?? S.current.alert,
  70. fontSize: 18,
  71. textAlign: TextAlign.center,
  72. isFontMedium: true,
  73. textColor: Colors.white,
  74. ).expanded(),
  75. const MyAssetImage(Assets.baseServiceDialogDeleteIcon,width: 25,height: 25.5,).onTap((){
  76. onCancel();
  77. },padding: 10)
  78. ],
  79. ),
  80. ),
  81. Container(
  82. width: double.infinity,
  83. padding: const EdgeInsets.only(top: 30),
  84. decoration: BoxDecoration(
  85. color: context.appColors.whiteSecondBG,
  86. borderRadius: const BorderRadius.only(
  87. bottomLeft: Radius.circular(15),
  88. bottomRight: Radius.circular(15),
  89. ),
  90. ),
  91. child: Column(
  92. children: [
  93. Scrollbar(
  94. child: ScrollConfiguration(
  95. behavior: NoShadowScrollBehavior(),
  96. child: SingleChildScrollView(
  97. child: message.isNotEmpty?MyTextView(
  98. message,
  99. fontSize: 18,
  100. textColor: context.appColors.textBlack,
  101. isFontRegular: true,
  102. textAlign: TextAlign.center,
  103. paddingLeft: 30,
  104. paddingRight: 30,
  105. ): (messageBuilder != null ? messageBuilder!(context) : Container()),
  106. ),
  107. ),
  108. ).constrained(maxHeight: contentBoxMaxHeight?? 300),
  109. Row(
  110. children: [
  111. const SizedBox(width: 18),
  112. Visibility(
  113. visible: isShowCancelBtn,
  114. child: Expanded(
  115. flex: 1,
  116. child: InkWell(
  117. onTap: () {
  118. onCancel();
  119. cancelAction?.call();
  120. },
  121. child: MyTextView(
  122. cancelTxt ?? S.current.no,
  123. fontSize: 16,
  124. isFontMedium: true,
  125. paddingTop: 13,
  126. marginRight: 15,
  127. paddingBottom: 13,
  128. textAlign: TextAlign.center,
  129. textColor: Colors.white,
  130. backgroundColor: context.appColors.orangeBG,
  131. cornerRadius: 7,
  132. ),
  133. )),
  134. ),
  135. Expanded(
  136. flex: 1,
  137. child: InkWell(
  138. onTap: () async {
  139. onCancel();
  140. confirmAction();
  141. },
  142. child: MyTextView(
  143. confirmTxt ?? S.current.yes,
  144. fontSize: 16,
  145. paddingTop: 13,
  146. paddingBottom: 13,
  147. isFontMedium: true,
  148. textAlign: TextAlign.center,
  149. textColor: Colors.white,
  150. backgroundColor: context.appColors.btnBgDefault,
  151. cornerRadius: 7,
  152. ),
  153. )),
  154. const SizedBox(width: 18),
  155. ],
  156. ).marginOnly(bottom: 30, top: 28),
  157. ],
  158. ),
  159. ),
  160. ],
  161. ).constrained(width: 300),
  162. );
  163. }
  164. //取消弹框
  165. void onCancel() async {
  166. SmartDialog.dismiss();
  167. }
  168. }