rewards_confirm_page.dart 16 KB

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