rewards_confirm_page.dart 15 KB

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