surprise_dialog.dart 11 KB

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