surprise_dialog.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  4. import 'package:get/get.dart';
  5. import 'package:keyboard/resource/string.gen.dart';
  6. import 'package:lottie/lottie.dart';
  7. import '../../../resource/assets.gen.dart';
  8. import '../../../resource/colors.gen.dart';
  9. import '../../../utils/styles.dart';
  10. import '../../../widget/horizontal_dashed_line.dart';
  11. import '../../../widget/vertical_dots.dart';
  12. import 'goods_surprise_controller.dart';
  13. class SurpriseDialog {
  14. static const String tag = 'SurpriseDialog';
  15. static void show({VoidCallback? clickConfirm,VoidCallback? clickCancel}) {
  16. SmartDialog.show(
  17. tag: tag,
  18. backType: SmartBackType.block,
  19. clickMaskDismiss: false,
  20. maskColor: ColorName.black70,
  21. onDismiss: () => Get.delete<GoodsSurpriseController>(),
  22. animationType: SmartAnimationType.centerScale_otherSlide,
  23. builder: (_) {
  24. final controller = Get.find<GoodsSurpriseController>();
  25. return Stack(
  26. children: [
  27. Positioned(
  28. top: 0,
  29. left: 0,
  30. right: 0,
  31. bottom: 0,
  32. child: Column(
  33. crossAxisAlignment: CrossAxisAlignment.center,
  34. mainAxisAlignment: MainAxisAlignment.center,
  35. children: [
  36. Stack(
  37. clipBehavior: Clip.none,
  38. children: [
  39. Container(
  40. width: 328.w,
  41. height: 290.h,
  42. decoration: BoxDecoration(
  43. image: DecorationImage(
  44. image: Assets.images.bgSurpriseDialog.provider(),
  45. fit: BoxFit.cover,
  46. ),
  47. ),
  48. child: Column(
  49. mainAxisAlignment: MainAxisAlignment.center,
  50. crossAxisAlignment: CrossAxisAlignment.center,
  51. children: [
  52. SizedBox(height: 23.h),
  53. Container(
  54. width: 240.w,
  55. height: 108.h,
  56. decoration: BoxDecoration(
  57. image: DecorationImage(
  58. image:
  59. Assets.images.bgSurpriseDialogPrices
  60. .provider(),
  61. fit: BoxFit.cover,
  62. ),
  63. ),
  64. child: Column(
  65. mainAxisAlignment: MainAxisAlignment.center,
  66. crossAxisAlignment: CrossAxisAlignment.center,
  67. children: [
  68. Obx(() {
  69. return _buildPricesPartOne(controller);
  70. }),
  71. HorizontalDashedLine(
  72. width: 200.w,
  73. color: Color(0xFFFF9451),
  74. strokeWidth: 2.h,
  75. dashLength: 5.w,
  76. dashSpace: 3.w,
  77. ),
  78. Obx(() {
  79. return Text(
  80. controller.firstAmount?.description ?? "",
  81. style: TextStyle(
  82. color: const Color(0xFFFFC172),
  83. fontSize: 10.sp,
  84. fontWeight: FontWeight.w400,
  85. height: 2,
  86. ),
  87. );
  88. }),
  89. ],
  90. ),
  91. ),
  92. SizedBox(height: 16.h),
  93. GestureDetector(
  94. onTap: () {
  95. clickConfirm?.call();
  96. SmartDialog.dismiss(tag: tag);
  97. },
  98. child: Container(
  99. width: 240.w,
  100. height: 60.h,
  101. decoration: BoxDecoration(
  102. image: DecorationImage(
  103. image:
  104. Assets.images.bgSurpriseDialogButton
  105. .provider(),
  106. fit: BoxFit.cover,
  107. ),
  108. ),
  109. child: Column(
  110. mainAxisAlignment: MainAxisAlignment.center,
  111. crossAxisAlignment: CrossAxisAlignment.center,
  112. children: [
  113. SizedBox(
  114. child: Assets
  115. .images
  116. .iconSurpriseDialogButton
  117. .image(width: 120.w, height: 20.h),
  118. ),
  119. Obx(() {
  120. int totalMilliseconds =
  121. controller.timeLeft.value;
  122. int minutes = (totalMilliseconds ~/ 6000);
  123. int seconds =
  124. (totalMilliseconds ~/ 100) % 60;
  125. int milliseconds =
  126. (totalMilliseconds % 100); // 毫秒
  127. return Row(
  128. mainAxisAlignment:
  129. MainAxisAlignment.center,
  130. crossAxisAlignment:
  131. CrossAxisAlignment.center,
  132. children: [
  133. _buildTimeBox(
  134. minutes.toString().padLeft(2, '0'),
  135. ),
  136. VerticalDots(
  137. height: 8.h,
  138. dotSize: 2.w,
  139. ),
  140. _buildTimeBox(
  141. seconds.toString().padLeft(2, '0'),
  142. ),
  143. VerticalDots(
  144. height: 8.h,
  145. dotSize: 2.w,
  146. ),
  147. _buildTimeBox(
  148. milliseconds.toString().padLeft(
  149. 2,
  150. '0',
  151. ),
  152. ),
  153. Text(
  154. StringName.surpriseDialogEndDesc,
  155. style: Styles.getTextStyleWhiteW400(
  156. 10.sp,
  157. ),
  158. ),
  159. ],
  160. );
  161. }),
  162. ],
  163. ),
  164. ),
  165. ),
  166. ],
  167. ),
  168. ),
  169. Positioned(
  170. top: -50,
  171. right: 0,
  172. left: 0,
  173. child: Assets.images.iconSurpriseDialogTitle.image(
  174. width: 264.w,
  175. height: 95.h,
  176. ),
  177. ),
  178. ],
  179. ),
  180. Container(
  181. margin: EdgeInsets.only(top: 24.h),
  182. child: GestureDetector(
  183. onTap: () {
  184. SmartDialog.dismiss(tag: tag);
  185. clickCancel?.call();
  186. },
  187. child: Assets.images.iconCharacterDialogClose.image(
  188. width: 40.r,
  189. height: 40.r,
  190. ),
  191. ),
  192. ),
  193. ],
  194. ),
  195. ),
  196. IgnorePointer(
  197. child: Lottie.asset(
  198. Assets.anim.animSurpriseDialogData,
  199. repeat: false,
  200. width: 360.w,
  201. ),
  202. ),
  203. ],
  204. );
  205. },
  206. );
  207. }
  208. static Widget _buildPricesPartOne(GoodsSurpriseController controller) {
  209. return Row(
  210. mainAxisAlignment: MainAxisAlignment.center,
  211. crossAxisAlignment: CrossAxisAlignment.center,
  212. children: [
  213. Text(
  214. controller.firstAmount?.priceDescNumber ?? "",
  215. style: TextStyle(
  216. color: Colors.white,
  217. fontSize: 48.sp,
  218. fontWeight: FontWeight.w700,
  219. ),
  220. ),
  221. Column(
  222. children: [
  223. Container(
  224. width: 30.w,
  225. height: 18.h,
  226. decoration: BoxDecoration(
  227. image: DecorationImage(
  228. image: Assets.images.iconSurpriseDialogOnly.provider(),
  229. fit: BoxFit.cover,
  230. ),
  231. ),
  232. child: Center(
  233. child: Text(
  234. StringName.surpriseDialogOnly,
  235. style: TextStyle(
  236. color: const Color(0xFFFF451D),
  237. fontSize: 11.sp,
  238. fontWeight: FontWeight.w500,
  239. ),
  240. ),
  241. ),
  242. ),
  243. Text(
  244. controller.firstAmount?.priceDescUnit ?? '',
  245. style: TextStyle(
  246. color: Colors.white,
  247. fontSize: 14.sp,
  248. fontWeight: FontWeight.w700,
  249. ),
  250. ),
  251. ],
  252. ),
  253. ],
  254. );
  255. }
  256. static Widget _buildTimeBox(String value) {
  257. return Container(
  258. width: 18.w,
  259. height: 15.h,
  260. decoration: ShapeDecoration(
  261. color: Colors.white,
  262. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.r)),
  263. ),
  264. child: Center(
  265. child: Text(value, style: Styles.getTextStyleBlack204W500(10.sp)),
  266. ),
  267. );
  268. }
  269. }