rewards_redeem_page.dart 15 KB

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