surprise_dialog.dart 11 KB

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