app_custom_dialog.dart 6.3 KB

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