rewards_my_page.dart 4.3 KB

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