rewards_my_page.dart 4.0 KB

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