rewards_confirm_page.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. import 'package:cs_resources/theme/app_colors_theme.dart';
  2. import 'package:domain/entity/rewards_detail_entity.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:auto_route/auto_route.dart';
  6. import 'package:flutter_hooks/flutter_hooks.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:router/ext/auto_router_extensions.dart';
  9. import 'package:shared/utils/log_utils.dart';
  10. import 'package:shared/utils/color_utils.dart';
  11. import 'package:widgets/ext/ex_widget.dart';
  12. import 'package:widgets/load_state_layout.dart';
  13. import 'package:widgets/my_appbar.dart';
  14. import 'package:widgets/my_load_image.dart';
  15. import 'package:widgets/my_text_view.dart';
  16. import 'package:widgets/shatter/picker_container.dart';
  17. import 'package:widgets/widget_export.dart';
  18. import 'package:cs_resources/generated/assets.dart';
  19. import '../../../router/page/rewards_page_router.dart';
  20. import './rewards_confirm_vm.dart';
  21. @RoutePage()
  22. class RewardsConfirmPage extends HookConsumerWidget {
  23. final int? id;
  24. const RewardsConfirmPage({Key? key, @PathParam('id') required this.id})
  25. : super(key: key);
  26. //启动当前页面
  27. static void startInstance({
  28. BuildContext? context,
  29. int? id,
  30. }) {
  31. if (context != null) {
  32. context.router.push(RewardsConfirmPageRoute(id: id));
  33. } else {
  34. appRouter.push(RewardsConfirmPageRoute(id: id));
  35. }
  36. }
  37. // listitem
  38. Widget _buildSaleItem(BuildContext context, WidgetRef ref, _vm, detailInfo) {
  39. String title = detailInfo!.title ?? "";
  40. List? resources = detailInfo!.resources ?? [];
  41. return Column(
  42. children: [
  43. Container(
  44. decoration: const BoxDecoration(
  45. color: Colors.white,
  46. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  47. boxShadow: [
  48. BoxShadow(
  49. color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
  50. ],
  51. ),
  52. width: MediaQuery.of(context).size.width - 30,
  53. // height: 420,
  54. // margin: const EdgeInsets.only(left: 15, right: 15, top: 12.5),
  55. child: Column(
  56. crossAxisAlignment: CrossAxisAlignment.start,
  57. mainAxisAlignment: MainAxisAlignment.start,
  58. children: [
  59. resources!.length > 0
  60. ? MyLoadImage(
  61. resources[0] ?? '',
  62. width: MediaQuery.of(context).size.width,
  63. height: 150,
  64. )
  65. : Container(),
  66. Column(
  67. crossAxisAlignment: CrossAxisAlignment.start,
  68. mainAxisAlignment: MainAxisAlignment.start,
  69. children: [
  70. Text(
  71. maxLines: 1, // 设置最大行数为2
  72. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  73. title,
  74. style: const TextStyle(
  75. fontSize: 17.0,
  76. color: Colors.black,
  77. fontWeight: FontWeight.w500),
  78. ),
  79. ],
  80. ).paddingOnly(left: 15, right: 15, top: 10, bottom: 30),
  81. ],
  82. )),
  83. ],
  84. ).marginOnly(left: 15, bottom: 15, right: 15);
  85. }
  86. Widget _buildDeal(BuildContext context, WidgetRef ref, _vm) {
  87. return Column(
  88. children: [
  89. Container(
  90. decoration: const BoxDecoration(
  91. color: Colors.white,
  92. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  93. boxShadow: [
  94. BoxShadow(
  95. color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
  96. ],
  97. ),
  98. width: MediaQuery.of(context).size.width - 30,
  99. child: Column(
  100. crossAxisAlignment: CrossAxisAlignment.start,
  101. children: [
  102. Row(
  103. mainAxisSize: MainAxisSize.min,
  104. mainAxisAlignment: MainAxisAlignment.start,
  105. crossAxisAlignment: CrossAxisAlignment.center,
  106. children: [
  107. const MyAssetImage(
  108. Assets.rewardsRewardsDetailDeal,
  109. width: 25,
  110. height: 25,
  111. ).marginOnly(right: 5),
  112. Text(
  113. 'Redeem Deal At',
  114. style: TextStyle(
  115. fontSize: 15.0,
  116. color: ColorUtils.string2Color('#000000'),
  117. fontWeight: FontWeight.w500),
  118. )
  119. ],
  120. ),
  121. Column(
  122. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  123. crossAxisAlignment: CrossAxisAlignment.center,
  124. children: [
  125. Text(
  126. '60 paya lebar rd, #09-13/17 paya lebar square, singapore 409051',
  127. maxLines: 2, // 设置最大行数为2
  128. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  129. style: TextStyle(
  130. fontSize: 15.0,
  131. color: ColorUtils.string2Color('#54638C'),
  132. fontWeight: FontWeight.w400),
  133. ),
  134. ],
  135. ),
  136. ],
  137. ).paddingOnly(left: 15, right: 15, top: 12, bottom: 20),
  138. ),
  139. ],
  140. ).marginOnly(left: 15, bottom: 15, right: 15);
  141. }
  142. Widget _buildPackage(BuildContext context, WidgetRef ref, _vm, detailInfo) {
  143. String redeemedStart = detailInfo.redeemedStart ?? "";
  144. String redeemedEnd = detailInfo.redeemedEnd ?? "";
  145. String redeemedDate = '$redeemedStart-$redeemedEnd';
  146. return Column(
  147. children: [
  148. Container(
  149. decoration: const BoxDecoration(
  150. color: Colors.white,
  151. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  152. boxShadow: [
  153. BoxShadow(
  154. color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
  155. ],
  156. ),
  157. width: MediaQuery.of(context).size.width - 30,
  158. child: Column(
  159. crossAxisAlignment: CrossAxisAlignment.start,
  160. children: [
  161. Row(
  162. mainAxisSize: MainAxisSize.min,
  163. mainAxisAlignment: MainAxisAlignment.start,
  164. crossAxisAlignment: CrossAxisAlignment.center,
  165. children: [
  166. const MyAssetImage(
  167. Assets.rewardsRewardsIconDatd,
  168. width: 15,
  169. height: 15,
  170. ).marginOnly(right: 10),
  171. Text(
  172. 'Redeem From',
  173. style: TextStyle(
  174. fontSize: 15.0,
  175. color: ColorUtils.string2Color('#000000'),
  176. fontWeight: FontWeight.w500),
  177. )
  178. ],
  179. ).marginOnly(bottom: 10),
  180. Column(
  181. crossAxisAlignment: CrossAxisAlignment.start,
  182. children: [
  183. Text(
  184. redeemedDate,
  185. style: TextStyle(
  186. fontSize: 15.0,
  187. color: ColorUtils.string2Color('#54638C'),
  188. fontWeight: FontWeight.w400),
  189. ),
  190. ],
  191. ),
  192. ],
  193. ).paddingOnly(left: 15, right: 15, top: 12, bottom: 20),
  194. ),
  195. ],
  196. ).marginOnly(left: 15, bottom: 15, right: 15);
  197. }
  198. Widget _buildNotice(BuildContext context, WidgetRef ref, _vm, detailInfo) {
  199. final state = ref.watch(rewardsConfirmVmProvider);
  200. int number = state.number ?? 0;
  201. int amount = state.amount ?? 0;
  202. int point = detailInfo.point ?? 0;
  203. int originalPoint = detailInfo.originalPoint ?? 0;
  204. return Column(
  205. children: [
  206. Container(
  207. decoration: const BoxDecoration(
  208. color: Colors.white,
  209. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  210. boxShadow: [
  211. BoxShadow(
  212. color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
  213. ],
  214. ),
  215. width: MediaQuery.of(context).size.width - 30,
  216. child: Column(
  217. crossAxisAlignment: CrossAxisAlignment.start,
  218. children: [
  219. Row(
  220. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  221. crossAxisAlignment: CrossAxisAlignment.center,
  222. children: [
  223. Text(
  224. 'Quantity:',
  225. style: TextStyle(
  226. fontSize: 15.0,
  227. color: ColorUtils.string2Color('#333333'),
  228. fontWeight: FontWeight.w400),
  229. ),
  230. Row(
  231. children: [
  232. const MyAssetImage(
  233. Assets.rewardsRewardsJian,
  234. width: 21,
  235. height: 21,
  236. ).onTap(() {
  237. _vm.numberDec();
  238. }),
  239. Text(
  240. '$number',
  241. style: TextStyle(
  242. fontSize: 19.0,
  243. color: ColorUtils.string2Color('#333333'),
  244. fontWeight: FontWeight.w500),
  245. ).marginOnly(left: 15, right: 15),
  246. const MyAssetImage(
  247. Assets.rewardsRewardsJia,
  248. width: 21,
  249. height: 21,
  250. ).onTap(() {
  251. _vm.numberAdd();
  252. }),
  253. ],
  254. ),
  255. ],
  256. ),
  257. Row(
  258. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  259. crossAxisAlignment: CrossAxisAlignment.center,
  260. children: [
  261. Text(
  262. 'Points:',
  263. style: TextStyle(
  264. fontSize: 15.0,
  265. color: ColorUtils.string2Color('#333333'),
  266. fontWeight: FontWeight.w400),
  267. ),
  268. Row(
  269. children: [
  270. Text(
  271. '$originalPoint',
  272. style: TextStyle(
  273. decoration: TextDecoration.lineThrough,
  274. decorationColor: ColorUtils.string2Color('#54638C'),
  275. decorationStyle: TextDecorationStyle.solid,
  276. fontSize: 14.0,
  277. color: ColorUtils.string2Color('#54638C'),
  278. fontWeight: FontWeight.w400),
  279. ),
  280. Text(
  281. '$point',
  282. style: TextStyle(
  283. fontSize: 19.0,
  284. color: ColorUtils.string2Color('#333333'),
  285. fontWeight: FontWeight.w500),
  286. ).marginOnly(left: 10),
  287. ],
  288. ),
  289. ],
  290. ).marginOnly(top: 30, bottom: 30),
  291. Row(
  292. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  293. crossAxisAlignment: CrossAxisAlignment.center,
  294. children: [
  295. Text(
  296. 'Amount:',
  297. style: TextStyle(
  298. fontSize: 15.0,
  299. color: ColorUtils.string2Color('#333333'),
  300. fontWeight: FontWeight.w400),
  301. ),
  302. Row(
  303. children: [
  304. Text(
  305. '$amount',
  306. style: TextStyle(
  307. fontSize: 19.0,
  308. color: ColorUtils.string2Color('#4161D0'),
  309. fontWeight: FontWeight.w500),
  310. ),
  311. ],
  312. ),
  313. ],
  314. ),
  315. ],
  316. ).paddingOnly(left: 15, right: 15, top: 30, bottom: 30),
  317. ),
  318. ],
  319. ).marginOnly(left: 15, bottom: 15, right: 15);
  320. }
  321. @override
  322. Widget build(BuildContext context, WidgetRef ref) {
  323. final _vm = ref.read(rewardsConfirmVmProvider.notifier);
  324. final state = ref.watch(rewardsConfirmVmProvider);
  325. RewardsDetailEntity? detailInfo = state.detailInfo;
  326. useEffect(() {
  327. // 组件挂载时执行 - 执行接口请求
  328. Future.microtask(() => _vm.initPageData(id: id));
  329. return () {
  330. // 组件卸载时执行
  331. Log.d("property_news_page 组件卸载时执行");
  332. };
  333. }, []);
  334. return Scaffold(
  335. appBar: MyAppBar.appBar(
  336. context,
  337. "Confirm Details",
  338. backgroundColor: context.appColors.whiteBG,
  339. ),
  340. body: LoadStateLayout(
  341. state: state.loadingState,
  342. errorMessage: state.errorMessage,
  343. errorRetry: () {
  344. _vm.retryRequest(id: id);
  345. },
  346. successWidget: Column(
  347. children: [
  348. Expanded(
  349. child: SingleChildScrollView(
  350. scrollDirection: Axis.vertical,
  351. physics: const BouncingScrollPhysics(),
  352. clipBehavior: Clip.none,
  353. child: Column(
  354. children: [
  355. Container(
  356. color: ColorUtils.string2Color('#F2F3F6'),
  357. padding: const EdgeInsets.only(top: 15),
  358. child: Column(
  359. children: [
  360. _buildSaleItem(context, ref, _vm, detailInfo),
  361. _buildDeal(context, ref, _vm),
  362. _buildPackage(context, ref, _vm, detailInfo),
  363. _buildNotice(context, ref, _vm, detailInfo),
  364. ],
  365. )),
  366. ],
  367. ))),
  368. Container(
  369. height: 50,
  370. color: ColorUtils.string2Color('#4161D0'),
  371. child: Flex(
  372. direction: Axis.horizontal,
  373. children: [
  374. Expanded(
  375. flex: 1,
  376. child: Container(
  377. color: ColorUtils.string2Color('#4161D0'),
  378. height: 100,
  379. child: Row(
  380. mainAxisAlignment: MainAxisAlignment.center,
  381. crossAxisAlignment: CrossAxisAlignment.center,
  382. children: [
  383. MyTextView(
  384. "Redeem",
  385. fontSize: 16,
  386. textColor: Colors.white,
  387. isFontMedium: true,
  388. ),
  389. ],
  390. ),
  391. ).onTap(() {
  392. // 去详情
  393. _vm.doDeleteAccount();
  394. }),
  395. ),
  396. ],
  397. ),
  398. )
  399. ],
  400. )),
  401. );
  402. }
  403. }