payment_page.dart 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import 'package:cpt_payment/modules/payment/payment_view_model.dart';
  2. import 'package:cs_resources/generated/assets.dart';
  3. import 'package:cs_resources/generated/l10n.dart';
  4. import 'package:cs_resources/theme/app_colors_theme.dart';
  5. import 'package:cs_resources/theme/theme_config.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:auto_route/auto_route.dart';
  8. import 'package:flutter/services.dart';
  9. import 'package:flutter_hooks/flutter_hooks.dart';
  10. import 'package:hooks_riverpod/hooks_riverpod.dart';
  11. import 'package:router/ext/auto_router_extensions.dart';
  12. import 'package:shared/utils/log_utils.dart';
  13. import 'package:widgets/ext/ex_widget.dart';
  14. import 'package:widgets/my_appbar.dart';
  15. import 'package:widgets/my_load_image.dart';
  16. import 'package:widgets/my_text_view.dart';
  17. import '../../../router/page/payment_page_router.dart';
  18. @RoutePage()
  19. class PaymentPage extends HookConsumerWidget {
  20. const PaymentPage({Key? key}) : super(key: key);
  21. //启动当前页面
  22. static void startInstance({BuildContext? context}) {
  23. if (context != null) {
  24. context.router.push(const PaymentPageRoute());
  25. } else {
  26. appRouter.push(const PaymentPageRoute());
  27. }
  28. }
  29. @override
  30. Widget build(BuildContext context, WidgetRef ref) {
  31. final viewModel = ref.watch(paymentViewModelProvider.notifier);
  32. int selectedInnerIndex = 1; // 1-3索引记录当前的值
  33. return Scaffold(
  34. appBar: MyAppBar.appBar(
  35. context,
  36. S.current.payment,
  37. backgroundColor: context.appColors.whiteBG,
  38. ),
  39. backgroundColor: context.appColors.backgroundDark,
  40. body: AutoTabsRouter.pageView(
  41. routes: const [
  42. InfoPageRoute(),
  43. CondoPaymentPageRoute(),
  44. CondoActivePageRoute(),
  45. CondoHistoryPageRoute(),
  46. ManagePageRoute(),
  47. ],
  48. builder: (context, child, pageController) {
  49. final tabsRouter = AutoTabsRouter.of(context);
  50. pageController.addListener(() {
  51. //监听赋值内部的选中索引
  52. if (tabsRouter.activeIndex >= 1 && tabsRouter.activeIndex <= 3) {
  53. selectedInnerIndex = tabsRouter.activeIndex;
  54. }
  55. });
  56. return Column(
  57. children: [
  58. Container(
  59. color: context.appColors.whiteBG,
  60. height: 120,
  61. child: Row(
  62. mainAxisAlignment: MainAxisAlignment.spaceAround,
  63. children: [
  64. _buildTopCategory(
  65. context,
  66. Assets.paymentInfoIcon,
  67. 34,
  68. 41,
  69. "Info",
  70. tabsRouter.activeIndex == 0,
  71. ).onTap(
  72. () {
  73. tabsRouter.setActiveIndex(0);
  74. },
  75. ),
  76. _buildTopCategory(
  77. context,
  78. Assets.paymentCondoIcon,
  79. 48,
  80. 43,
  81. "Condo",
  82. tabsRouter.activeIndex == 1 || tabsRouter.activeIndex == 2 || tabsRouter.activeIndex == 3,
  83. ).onTap(
  84. () {
  85. tabsRouter.setActiveIndex(selectedInnerIndex);
  86. },
  87. ),
  88. _buildTopCategory(
  89. context,
  90. Assets.paymentManageIcon,
  91. 52,
  92. 46.5,
  93. "Manage",
  94. tabsRouter.activeIndex == 4,
  95. ).onTap(
  96. () {
  97. tabsRouter.setActiveIndex(4);
  98. },
  99. ),
  100. ],
  101. ),
  102. ),
  103. Expanded(
  104. child: Stack(
  105. children: [
  106. //真正页面
  107. child,
  108. //顶部的子Tab
  109. Visibility(
  110. visible: tabsRouter.activeIndex >= 1 && tabsRouter.activeIndex <= 3,
  111. child: Row(
  112. mainAxisAlignment: MainAxisAlignment.spaceAround,
  113. children: [
  114. _buildInnerTab(
  115. context,
  116. S.current.payment,
  117. tabsRouter.activeIndex == 1,
  118. ).onTap(() {
  119. tabsRouter.setActiveIndex(1);
  120. }),
  121. _buildInnerTab(
  122. context,
  123. S.current.facility_active,
  124. tabsRouter.activeIndex == 2,
  125. ).onTap(() {
  126. tabsRouter.setActiveIndex(2);
  127. }),
  128. _buildInnerTab(
  129. context,
  130. S.current.history,
  131. tabsRouter.activeIndex == 3,
  132. ).onTap(() {
  133. tabsRouter.setActiveIndex(3);
  134. }),
  135. ],
  136. ).marginOnly(top: 14, bottom: 17),
  137. ),
  138. ],
  139. ),
  140. ),
  141. ],
  142. );
  143. },
  144. ),
  145. );
  146. }
  147. //顶部的Tab布局
  148. Widget _buildTopCategory(BuildContext context, String iconPath, double iconWidth, double iconHeight, String title, bool isSelected) {
  149. return Column(
  150. mainAxisAlignment: MainAxisAlignment.center,
  151. crossAxisAlignment: CrossAxisAlignment.center,
  152. children: <Widget>[
  153. Container(
  154. width: 70,
  155. height: 70,
  156. decoration: BoxDecoration(
  157. color: context.appColors.lightBlueBg, // 设置圆形背景颜色
  158. shape: BoxShape.circle, // 设置为圆形
  159. boxShadow: isSelected
  160. ? [
  161. BoxShadow(
  162. color: context.appColors.tabLightBlueShadow, // 设置阴影颜色
  163. blurRadius: 5, // 设置模糊半径
  164. spreadRadius: 0.05, // 控制阴影扩散
  165. offset: const Offset(0, 4), // 设置阴影偏移量
  166. ),
  167. ]
  168. : [], // 未选中时无阴影,
  169. ),
  170. child: Center(
  171. child: MyAssetImage(iconPath, width: iconWidth, height: iconHeight),
  172. ),
  173. ),
  174. const SizedBox(height: 7),
  175. MyTextView(
  176. title,
  177. fontSize: 15,
  178. isFontMedium: true,
  179. textColor: isSelected ? context.appColors.tabTextSelectedDefault : context.appColors.tabTextUnSelectedDefault,
  180. ),
  181. ],
  182. );
  183. }
  184. //内部的Tab布局
  185. Widget _buildInnerTab(BuildContext context, String title, bool isSelected) {
  186. return MyTextView(
  187. title,
  188. fontSize: 16,
  189. isFontMedium: true,
  190. textColor: isSelected ? Colors.white : context.appColors.tabTextUnSelectedDefault,
  191. backgroundColor: isSelected ? context.appColors.btnBgDefault : Colors.transparent,
  192. cornerRadius: 16.5,
  193. paddingLeft: 20,
  194. paddingRight: 20,
  195. paddingTop: 8,
  196. paddingBottom: 8,
  197. );
  198. }
  199. }