rewards_my_page.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import 'package:cs_resources/theme/app_colors_theme.dart';
  2. import 'package:flutter/material.dart';
  3. // ignore: depend_on_referenced_packages
  4. import 'package:auto_route/auto_route.dart';
  5. import 'package:hooks_riverpod/hooks_riverpod.dart';
  6. import 'package:router/ext/auto_router_extensions.dart';
  7. import 'package:shared/utils/color_utils.dart';
  8. import 'package:shared/utils/log_utils.dart';
  9. import 'package:widgets/my_load_image.dart';
  10. import 'package:widgets/ext/ex_widget.dart';
  11. import 'package:widgets/my_text_view.dart';
  12. import 'package:widgets/my_appbar.dart';
  13. import '../../router/page/rewards_page_router.dart';
  14. import './rewards_my_vm.dart';
  15. @RoutePage()
  16. class RewardsMyPage extends HookConsumerWidget {
  17. const RewardsMyPage({Key? key}) : super(key: key);
  18. //启动当前页面
  19. static void startInstance({BuildContext? context}) {
  20. if (context != null) {
  21. context.router.push(const RewardsMyPageRoute());
  22. } else {
  23. appRouter.push(const RewardsMyPageRoute());
  24. }
  25. }
  26. // 顶部tab 切换
  27. Widget _buildTopSection(
  28. BuildContext context, WidgetRef ref, _vm, tabsRouter) {
  29. final topSectionsData = _vm.topSectionsData;
  30. final currentTabIdx = tabsRouter.activeIndex;
  31. return Container(
  32. color: Colors.white,
  33. child: Center(
  34. child: Row(
  35. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  36. crossAxisAlignment: CrossAxisAlignment.center,
  37. children: List.generate(topSectionsData.length, (index) {
  38. final item = topSectionsData[index];
  39. return Container(
  40. width:
  41. MediaQuery.of(context).size.width / topSectionsData.length -
  42. 30,
  43. height: 43,
  44. padding: const EdgeInsets.only(
  45. top: 10, bottom: 10, left: 10, right: 10),
  46. decoration: index == currentTabIdx
  47. ? BoxDecoration(
  48. color: index == currentTabIdx
  49. ? context.appColors.btnBgDefault
  50. : ColorUtils.string2Color("#F2F3F6"),
  51. borderRadius: BorderRadius.circular(20),
  52. boxShadow: [
  53. BoxShadow(
  54. color: Colors.grey.withOpacity(0.5),
  55. spreadRadius: 1,
  56. blurRadius: 5,
  57. offset:
  58. const Offset(0, 2), // changes position of shadow
  59. ),
  60. ],
  61. )
  62. : null,
  63. child: Row(
  64. children: [
  65. Expanded(
  66. child: Container(
  67. alignment: Alignment.center,
  68. child: MyTextView(
  69. item['title'],
  70. fontSize: 16,
  71. textAlign: TextAlign.center,
  72. isFontMedium: true,
  73. textColor: index == currentTabIdx
  74. ? Colors.white
  75. : ColorUtils.string2Color("#000000"),
  76. ),
  77. ).onTap(
  78. () {
  79. tabsRouter.setActiveIndex(index);
  80. },
  81. type: ClickType.throttle,
  82. ),
  83. ),
  84. ],
  85. ),
  86. ).marginOnly(left: 20, right: 0, top: 10, bottom: 10);
  87. }),
  88. ),
  89. ),
  90. );
  91. }
  92. @override
  93. Widget build(BuildContext context, WidgetRef ref) {
  94. final _vm = ref.read(rewardsMyVmProvider.notifier);
  95. return Scaffold(
  96. appBar: MyAppBar.appBar(
  97. context,
  98. "My Rewards",
  99. backgroundColor: context.appColors.whiteBG,
  100. ),
  101. body: AutoTabsRouter.pageView(
  102. routes: const [
  103. RewardsMyActivePageRoute(),
  104. RewardsMyExpiredPageRoute(),
  105. RewardsMyUsedPageRoute(),
  106. ],
  107. builder: (context, child, pageController) {
  108. final tabsRouter = AutoTabsRouter.of(context);
  109. return Column(
  110. children: [
  111. _buildTopSection(context, ref, _vm, tabsRouter),
  112. Expanded(
  113. child: child,
  114. ),
  115. ],
  116. );
  117. },
  118. ));
  119. }
  120. }