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