app_custom_dialog.dart 5.7 KB

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