rewards_home_page.dart 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. import 'package:cpt_rewards/modules/rewards_address/rewards_address_page.dart';
  2. import 'package:cpt_rewards/modules/rewards_code/rewards_code_page.dart';
  3. import 'package:cpt_rewards/modules/rewards_detail/rewards_detail_page.dart';
  4. import 'package:cpt_rewards/modules/rewards_list/rewards_list_page.dart';
  5. import 'package:cpt_rewards/modules/rewards_my/rewards_my_page.dart';
  6. import 'package:cpt_rewards/modules/rewards_search/rewards_search_page.dart';
  7. import 'package:cs_resources/generated/assets.dart';
  8. import 'package:cs_resources/generated/l10n.dart';
  9. import 'package:cs_resources/theme/app_colors_theme.dart';
  10. import 'package:cs_resources/theme/theme_config.dart';
  11. import 'package:domain/entity/rewards_category_entity.dart';
  12. import 'package:domain/entity/rewards_home_entity.dart';
  13. import 'package:flutter/material.dart';
  14. import 'package:auto_route/auto_route.dart';
  15. import 'package:flutter/services.dart';
  16. import 'package:flutter_hooks/flutter_hooks.dart';
  17. import 'package:hooks_riverpod/hooks_riverpod.dart';
  18. import 'package:plugin_platform/engine/image/image_nine_grid.dart';
  19. import 'package:router/ext/auto_router_extensions.dart';
  20. import 'package:shared/utils/color_utils.dart';
  21. import 'package:shared/utils/log_utils.dart';
  22. import 'package:widgets/ext/ex_widget.dart';
  23. import 'package:widgets/load_state_layout.dart';
  24. import 'package:widgets/my_appbar.dart';
  25. import 'package:widgets/my_load_image.dart';
  26. import '../../../router/page/rewards_page_router.dart';
  27. import './rewards_home_vm.dart';
  28. @RoutePage()
  29. class RewardsHomePage extends HookConsumerWidget {
  30. final int? points;
  31. const RewardsHomePage({Key? key, @PathParam('points') required this.points}) : super(key: key);
  32. //启动当前页面
  33. static void startInstance({
  34. BuildContext? context,
  35. int? points,
  36. }) {
  37. if (context != null) {
  38. context.router.push(RewardsHomePageRoute(points: points));
  39. } else {
  40. appRouter.push(RewardsHomePageRoute(points: points));
  41. }
  42. }
  43. Widget _buildTop(BuildContext context, WidgetRef ref, _vm) {
  44. int? point = points ?? 0;
  45. // String available = '$point'
  46. return Container(
  47. decoration: BoxDecoration(
  48. border: Border(
  49. bottom: BorderSide(
  50. color: ColorUtils.string2Color('#4161D0'), // 设置bottom边框的颜色
  51. width: 45.0, // 设置bottom边框的宽度
  52. )),
  53. borderRadius: const BorderRadius.only(
  54. topLeft: Radius.circular(0.0),
  55. topRight: Radius.circular(0.0),
  56. bottomLeft: Radius.circular(30.0),
  57. bottomRight: Radius.circular(30.0),
  58. ), // 圆角
  59. ),
  60. child: Column(
  61. crossAxisAlignment: CrossAxisAlignment.start,
  62. children: [
  63. Row(
  64. crossAxisAlignment: CrossAxisAlignment.center,
  65. mainAxisAlignment: MainAxisAlignment.center,
  66. children: [
  67. Text(
  68. '$point ${S.current.available_points}',
  69. style: const TextStyle(fontSize: 18.0, color: Colors.white, fontWeight: FontWeight.w500), // 设置字体大小
  70. ).paddingOnly(left: 10, top: 0, bottom: 13),
  71. ],
  72. ),
  73. Row(
  74. crossAxisAlignment: CrossAxisAlignment.center,
  75. mainAxisAlignment: MainAxisAlignment.center,
  76. children: [
  77. Container(
  78. decoration: BoxDecoration(
  79. border: Border.all(color: Colors.white, width: 1), // 边框
  80. borderRadius: BorderRadius.circular(8), // 圆角
  81. ),
  82. child: Text(
  83. S.current.my_rewards,
  84. style: const TextStyle(fontSize: 15.0, color: Colors.white, fontWeight: FontWeight.w400), // 设置字体大小
  85. ).paddingOnly(left: 10, top: 7, bottom: 7, right: 10).onTap(() {
  86. RewardsMyPage.startInstance();
  87. }),
  88. ),
  89. // Row(
  90. // crossAxisAlignment: CrossAxisAlignment.center,
  91. // mainAxisAlignment: MainAxisAlignment.center,
  92. // children: [
  93. // const MyAssetImage(
  94. // Assets.rewardsRewardsY,
  95. // width: 26,
  96. // height: 26,
  97. // ),
  98. // Text(
  99. // 'Bronze',
  100. // style: TextStyle(
  101. // fontSize: 17.0,
  102. // color: ColorUtils.string2Color('#FFCC00'),
  103. // fontWeight: FontWeight.w500), // 设置字体大小
  104. // ).marginOnly(
  105. // left: 9,
  106. // right: 7,
  107. // ),
  108. // const MyAssetImage(
  109. // Assets.rewardsRewardsRight,
  110. // width: 7,
  111. // height: 12,
  112. // ),
  113. // ],
  114. // )
  115. ],
  116. ).paddingOnly(left: 10)
  117. ],
  118. )
  119. .paddingOnly(top: 8, left: 5, right: 15, bottom: 8)
  120. .border(bottom: 0, color: ColorUtils.string2Color('#4161D0'))
  121. .backgroundColor(ColorUtils.string2Color('#4161D0')));
  122. }
  123. Widget _buildSearch(BuildContext context, WidgetRef ref, _vm) {
  124. // List itemsList = _vm.state.list.toList();
  125. return Container(
  126. width: MediaQuery.of(context).size.width - 30,
  127. height: 50,
  128. decoration: BoxDecoration(
  129. color: Colors.white,
  130. borderRadius: BorderRadius.circular(10),
  131. ),
  132. child: Row(
  133. crossAxisAlignment: CrossAxisAlignment.center,
  134. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  135. children: [
  136. Text(
  137. S.current.search,
  138. style: TextStyle(fontSize: 15.0, color: ColorUtils.string2Color('#C7CDE3'), fontWeight: FontWeight.w500), // 设置字体大小
  139. ),
  140. const MyAssetImage(
  141. Assets.rewardsRewardsIndexSearch,
  142. width: 21,
  143. height: 21,
  144. ),
  145. ],
  146. ).paddingOnly(left: 15, right: 15),
  147. ).onTap(() {
  148. RewardsSearchPage.startInstance();
  149. });
  150. }
  151. Widget _buildSwiper(BuildContext context, WidgetRef ref, _vm) {
  152. // List itemsList = _vm.state.lists.toList();
  153. final state = ref.watch(rewardsHomeVmProvider);
  154. List<Map<String, dynamic>>? itemsList = state.categoryList;
  155. return Container(
  156. transform: Matrix4.translationValues(0.0, -10.0, 0.0),
  157. // color: Colors.white,
  158. height: 110,
  159. decoration: const BoxDecoration(
  160. color: Colors.white,
  161. borderRadius: const BorderRadius.only(
  162. topLeft: Radius.circular(10.0),
  163. topRight: Radius.circular(0.0),
  164. bottomLeft: Radius.circular(10.0),
  165. bottomRight: Radius.circular(0.0),
  166. ),
  167. boxShadow: [BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)],
  168. ),
  169. child: ClipRect(
  170. child: SingleChildScrollView(
  171. scrollDirection: Axis.horizontal,
  172. physics: const BouncingScrollPhysics(),
  173. clipBehavior: Clip.none,
  174. child: Row(
  175. crossAxisAlignment: CrossAxisAlignment.center,
  176. mainAxisAlignment: MainAxisAlignment.center,
  177. children: List.generate(itemsList!.length, (index) {
  178. final item = itemsList[index];
  179. return Column(
  180. crossAxisAlignment: CrossAxisAlignment.center,
  181. mainAxisAlignment: MainAxisAlignment.center,
  182. children: [
  183. MyLoadImage(
  184. item['icon'] ?? '',
  185. width: 70,
  186. height: 70,
  187. ),
  188. Text(
  189. item['name']!,
  190. style: TextStyle(fontSize: 14.0, color: ColorUtils.string2Color('#000001'), fontWeight: FontWeight.w600), // 设置字体大小
  191. ),
  192. ],
  193. ).marginOnly(right: 5).onTap(() {
  194. RewardsListPage.startInstance();
  195. });
  196. }),
  197. ).marginOnly(left: 15, right: 15),
  198. )),
  199. ).paddingOnly(left: 15);
  200. }
  201. Widget _buildRecommend(BuildContext context, WidgetRef ref, _vm, list) {
  202. return list['rewards'].length > 0
  203. ? Container(
  204. child: Column(
  205. children: [
  206. Row(
  207. crossAxisAlignment: CrossAxisAlignment.center,
  208. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  209. children: [
  210. Text(
  211. list?['name'] ?? '',
  212. style: TextStyle(fontSize: 17.0, color: ColorUtils.string2Color('#000001'), fontWeight: FontWeight.w500), // 设置字体大小
  213. ),
  214. Text(
  215. S.current.see_all,
  216. style: TextStyle(fontSize: 17.0, color: ColorUtils.string2Color('#4161D0'), fontWeight: FontWeight.w500), // 设置字体大小
  217. ).onTap(() {
  218. RewardsListPage.startInstance();
  219. }),
  220. ],
  221. ).marginOnly(bottom: 15),
  222. Row(
  223. crossAxisAlignment: CrossAxisAlignment.center,
  224. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  225. children: List.generate(list['rewards'].length, (index) {
  226. double hg = 70;
  227. return Container(
  228. width: MediaQuery.of(context).size.width / 2 - 25,
  229. height: 155,
  230. decoration: const BoxDecoration(
  231. color: Colors.white,
  232. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  233. boxShadow: [BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)],
  234. ),
  235. child: ClipRRect(
  236. borderRadius: const BorderRadius.all(Radius.circular(6.0)), child: _buildItem(context, ref, _vm, hg, list['rewards'][index])));
  237. }))
  238. ],
  239. ),
  240. ).paddingOnly(left: 15, right: 15, top: 10)
  241. : Container();
  242. }
  243. Widget _buildHottest(BuildContext context, WidgetRef ref, _vm) {
  244. return Container(
  245. child: Column(
  246. children: [
  247. Row(
  248. crossAxisAlignment: CrossAxisAlignment.center,
  249. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  250. children: [
  251. Text(
  252. S.current.hottest,
  253. style: TextStyle(fontSize: 17.0, color: ColorUtils.string2Color('#000001'), fontWeight: FontWeight.w500), // 设置字体大小
  254. ),
  255. Text(
  256. S.current.see_all,
  257. style: TextStyle(fontSize: 17.0, color: ColorUtils.string2Color('#4161D0'), fontWeight: FontWeight.w500), // 设置字体大小
  258. ).onTap(() {
  259. RewardsListPage.startInstance();
  260. }),
  261. ],
  262. ).marginOnly(bottom: 15),
  263. Row(
  264. crossAxisAlignment: CrossAxisAlignment.center,
  265. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  266. children: List.generate(2, (index) {
  267. double hg = 70;
  268. return Container(
  269. width: MediaQuery.of(context).size.width / 2 - 25,
  270. height: 185,
  271. decoration: const BoxDecoration(
  272. color: Colors.white,
  273. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  274. boxShadow: [BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)],
  275. ),
  276. child: _buildItem(context, ref, _vm, hg, {}));
  277. }))
  278. ],
  279. ),
  280. ).paddingOnly(left: 15, right: 15, top: 10);
  281. }
  282. Widget _buildItem(BuildContext context, WidgetRef ref, _vm, height, item) {
  283. double hg = height;
  284. num point = item['point'] ?? 0;
  285. num originalPoint = item['original_point'] ?? 0;
  286. int id = item['id'];
  287. return Column(
  288. children: [
  289. MyLoadImage(
  290. item?['resources']?[0] ?? '',
  291. width: MediaQuery.of(context).size.width,
  292. height: hg,
  293. // cornerRadius:6,
  294. ),
  295. Column(
  296. crossAxisAlignment: CrossAxisAlignment.start,
  297. children: [
  298. Text(
  299. maxLines: 1, // 设置最大行数为2
  300. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  301. item?['name'] ?? '',
  302. style: const TextStyle(fontSize: 15.0, color: Colors.black, fontWeight: FontWeight.w500),
  303. ).marginOnly(bottom: 5),
  304. Row(
  305. children: [
  306. Text(
  307. '$point',
  308. style: const TextStyle(fontSize: 18.0, color: Colors.black, fontWeight: FontWeight.w500),
  309. ),
  310. Text(
  311. '$originalPoint',
  312. style: TextStyle(
  313. decoration: TextDecoration.lineThrough,
  314. decorationColor: ColorUtils.string2Color('#808DAF'),
  315. decorationStyle: TextDecorationStyle.solid,
  316. fontSize: 13.0,
  317. color: ColorUtils.string2Color('#808DAF'),
  318. fontWeight: FontWeight.w400),
  319. ).marginOnly(left: 5, right: 5),
  320. Text(
  321. S.current.points,
  322. style: const TextStyle(fontSize: 13.0, color: Colors.black, fontWeight: FontWeight.w400),
  323. ),
  324. ],
  325. )
  326. ],
  327. ).paddingOnly(top: 12, left: 12, right: 12)
  328. ],
  329. ).onTap(() {
  330. RewardsDetailPage.startInstance(id: id);
  331. });
  332. }
  333. Widget _buildFood(BuildContext context, WidgetRef ref, _vm, list) {
  334. return list['rewards'].length > 0
  335. ? Container(
  336. child: Column(
  337. children: [
  338. Row(
  339. crossAxisAlignment: CrossAxisAlignment.center,
  340. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  341. children: [
  342. Text(
  343. list?['name'] ?? '',
  344. style: TextStyle(fontSize: 17.0, color: ColorUtils.string2Color('#000001'), fontWeight: FontWeight.w500), // 设置字体大小
  345. ),
  346. Text(
  347. S.current.see_all,
  348. style: TextStyle(fontSize: 17.0, color: ColorUtils.string2Color('#4161D0'), fontWeight: FontWeight.w500), // 设置字体大小
  349. ).onTap(() {
  350. RewardsListPage.startInstance();
  351. }),
  352. ],
  353. ).marginOnly(bottom: 15),
  354. Row(
  355. crossAxisAlignment: CrossAxisAlignment.center,
  356. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  357. children: List.generate(list['rewards'].length, (index) {
  358. double hg = 70;
  359. return Container(
  360. width: MediaQuery.of(context).size.width / 2 - 25,
  361. height: 155,
  362. decoration: const BoxDecoration(
  363. color: Colors.white,
  364. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  365. boxShadow: [BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)],
  366. ),
  367. child: ClipRRect(
  368. borderRadius: const BorderRadius.all(Radius.circular(6.0)), child: _buildItem(context, ref, _vm, hg, list['rewards'][index])));
  369. }))
  370. ],
  371. ),
  372. ).paddingOnly(left: 15, right: 15, top: 10)
  373. : Container();
  374. }
  375. Widget _buildBest(BuildContext context, WidgetRef ref, _vm, list) {
  376. return list['rewards'].length > 0
  377. ? Container(
  378. child: Column(
  379. children: [
  380. Row(
  381. crossAxisAlignment: CrossAxisAlignment.center,
  382. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  383. children: [
  384. Text(
  385. S.current.best_offers_in_singapore,
  386. style: TextStyle(fontSize: 17.0, color: ColorUtils.string2Color('#000001'), fontWeight: FontWeight.w500), // 设置字体大小
  387. ),
  388. Text(
  389. S.current.see_all,
  390. style: TextStyle(fontSize: 17.0, color: ColorUtils.string2Color('#4161D0'), fontWeight: FontWeight.w500), // 设置字体大小
  391. ),
  392. ],
  393. ).marginOnly(bottom: 15),
  394. Column(
  395. crossAxisAlignment: CrossAxisAlignment.center,
  396. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  397. children: List.generate(list['rewards'].length, (index) {
  398. double hg = 140;
  399. return Container(
  400. // width: MediaQuery.of(context).size.width / 2 - 25,
  401. height: 220,
  402. decoration: const BoxDecoration(
  403. color: Colors.white,
  404. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  405. boxShadow: [BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)],
  406. ),
  407. child: ClipRRect(
  408. borderRadius: const BorderRadius.all(Radius.circular(6.0)), child: _buildItem(context, ref, _vm, hg, list['rewards'][index])))
  409. .marginOnly(bottom: 13);
  410. }))
  411. ],
  412. ),
  413. ).paddingOnly(left: 15, right: 15, top: 10)
  414. : Container();
  415. }
  416. @override
  417. Widget build(BuildContext context, WidgetRef ref) {
  418. final _vm = ref.read(rewardsHomeVmProvider.notifier);
  419. final state = ref.watch(rewardsHomeVmProvider);
  420. useEffect(() {
  421. // 组件挂载时执行 - 执行接口请求
  422. Future.microtask(() => _vm.initPageData());
  423. return () {
  424. // 组件卸载时执行s
  425. Log.d("property_news_page 组件卸载时执行");
  426. };
  427. }, []);
  428. return Scaffold(
  429. appBar: MyAppBar.appBar(
  430. context,
  431. "",
  432. backIconPath: Assets.rewardsRewardsBack,
  433. backIconWidth: 32.0,
  434. backIconHeight: 32.0,
  435. titleColor: Colors.white,
  436. titleDarkColor: Colors.white,
  437. showBackButton: true,
  438. backgroundColor: context.appColors.btnBgDefault,
  439. systemUiOverlayStyle: MediaQuery.of(context).platformBrightness == Brightness.dark
  440. ? ThemeConfig.systemUiOverlayStyleDarkTheme
  441. : ThemeConfig.systemUiOverlayStyleLightThemeWhite,
  442. ),
  443. body: Column(children: [
  444. Expanded(
  445. child: LoadStateLayout(
  446. state: state.loadingState,
  447. errorMessage: state.errorMessage,
  448. errorRetry: () {
  449. _vm.retryRequest();
  450. },
  451. successWidget: SingleChildScrollView(
  452. scrollDirection: Axis.vertical,
  453. physics: const BouncingScrollPhysics(),
  454. clipBehavior: Clip.none,
  455. child: state.list.length > 0
  456. ? Column(
  457. children: [
  458. Stack(clipBehavior: Clip.none, children: <Widget>[
  459. _buildTop(context, ref, _vm),
  460. // GestureDetector(
  461. // onTap: () {
  462. // print('第二个元素被点击'); // 这个会被触发。
  463. // },
  464. // child:Container(
  465. // transform:Matrix4.translationValues(0.0,210.0,0.0),child: _buildSearch(context,ref,_vm)//使用负数
  466. // ).paddingOnly(left:15,right:15))
  467. // Container(
  468. // // transform: Matrix4.translationValues(0.0, -25.0, 0.0),
  469. // child: _buildSearch(context, ref, _vm), // 使用负数margin
  470. // ).paddingOnly(left: 15, right: 15),
  471. Positioned(
  472. // 通过 Positioned 来确保它在红色容器的上方。
  473. left: 0, // 根据需要调整位置。
  474. bottom: -12, // 根据需要调整位置。
  475. child: GestureDetector(
  476. onTap: () {
  477. RewardsSearchPage.startInstance();
  478. },
  479. child: _buildSearch(context, ref, _vm),
  480. ).paddingOnly(left: 15, right: 15),
  481. ),
  482. ]).paddingOnly(bottom: 42),
  483. _buildSwiper(context, ref, _vm),
  484. _buildRecommend(context, ref, _vm, state.list![0]).marginOnly(bottom: 15),
  485. // _buildHottest(context, ref, _vm).marginOnly(bottom: 15),
  486. _buildFood(context, ref, _vm, state.list![2]).marginOnly(bottom: 15),
  487. _buildBest(context, ref, _vm, state.list![1]).marginOnly(bottom: 15),
  488. ],
  489. )
  490. : const Column()),
  491. )),
  492. ]).backgroundColor(ColorUtils.string2Color('#F2F3F6')),
  493. );
  494. }
  495. }