property_page.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import 'package:cs_resources/generated/assets.dart';
  2. import 'package:cs_resources/generated/l10n.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:auto_route/auto_route.dart';
  6. import 'package:flutter_hooks/flutter_hooks.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:router/ext/auto_router_extensions.dart';
  9. import 'package:shared/utils/color_utils.dart';
  10. import 'package:shared/utils/log_utils.dart';
  11. import 'package:widgets/my_load_image.dart';
  12. import 'package:widgets/ext/ex_widget.dart';
  13. import 'package:widgets/my_text_view.dart';
  14. import 'package:widgets/my_appbar.dart';
  15. import '../../../router/page/property_page_router.dart';
  16. import '../vm/property_vm.dart';
  17. final tabsRouterKey = GlobalKey<AutoTabsRouterState>();
  18. @RoutePage()
  19. class PropertyPage extends HookConsumerWidget {
  20. const PropertyPage({Key? key}) : super(key: key);
  21. //启动当前页面
  22. static void startInstance({BuildContext? context}) {
  23. if (context != null) {
  24. context.router.push(const PropertyPageRoute());
  25. } else {
  26. appRouter.push(const PropertyPageRoute());
  27. }
  28. }
  29. // 顶部tab 切换
  30. Widget _buildTopSection(BuildContext context, WidgetRef ref, _vm, tabsRouter) {
  31. final topSectionsData = _vm.topSectionsData;
  32. final currentTabIdx = tabsRouter.activeIndex;
  33. return Center(
  34. child: Container(
  35. color: context.appColors.whiteBG,
  36. width: MediaQuery.of(context).size.width,
  37. padding: const EdgeInsets.only(top: 0, bottom: 25),
  38. child: Row(
  39. mainAxisAlignment: MainAxisAlignment.center,
  40. crossAxisAlignment: CrossAxisAlignment.center,
  41. mainAxisSize: MainAxisSize.max,
  42. children: List.generate(topSectionsData.length, (index) {
  43. final item = topSectionsData[index];
  44. return Expanded(
  45. child: Column(
  46. mainAxisSize: MainAxisSize.max,
  47. mainAxisAlignment: MainAxisAlignment.spaceAround,
  48. children: [
  49. Container(
  50. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  51. // height: 70,
  52. decoration: BoxDecoration(
  53. color: ColorUtils.string2Color("#F0F8FF"),
  54. shape: BoxShape.circle, // 设置为圆形
  55. boxShadow: tabsRouter.activeIndex == index ? [
  56. BoxShadow(
  57. color: context.appColors.tabLightBlueShadow, // 设置阴影颜色
  58. blurRadius: 5, // 设置模糊半径
  59. spreadRadius: 0.05, // 控制阴影扩散
  60. offset: const Offset(0, 4), // 设置阴影偏移量
  61. ),
  62. ] : [],// 未选中时无阴影,
  63. ),
  64. child: MyAssetImage(
  65. item['icon'],
  66. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  67. height: 70,
  68. ).onTap(() {
  69. tabsRouter.setActiveIndex(index);
  70. },
  71. type: ClickType.throttle,
  72. ),
  73. ),
  74. SizedBox.fromSize(size: const Size(0, 9)),
  75. MyTextView(
  76. item['title'],
  77. maxLines: 1, // 设置最大行数为2
  78. isTextEllipsis: true, // 超出部分用省略号表示
  79. fontSize: 13,
  80. textColor: currentTabIdx == index ? ColorUtils.string2Color('#4161D0'):context.appColors.textBlack,
  81. isFontMedium: true,
  82. ),
  83. ],
  84. ),
  85. );
  86. }),
  87. ),
  88. ),
  89. );
  90. }
  91. @override
  92. Widget build(BuildContext context, WidgetRef ref) {
  93. final _vm = ref.read(propertyVmProvider.notifier);
  94. final state = ref.watch(propertyVmProvider);
  95. final isCollection = useState<bool>(false);
  96. useEffect((){
  97. WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
  98. if(tabsRouterKey.currentState?.controller != null){
  99. tabsRouterKey.currentState?.controller?.addListener((){
  100. _vm.tabsRouterChange();
  101. });
  102. }
  103. });
  104. return (){
  105. Log.d("CommunityPage dispose");
  106. tabsRouterKey.currentState?.controller?.removeListener(_vm.tabsRouterChange);
  107. };
  108. },[]);
  109. return Scaffold(
  110. appBar: MyAppBar.appBar(
  111. context,
  112. S.current.property,
  113. backgroundColor: context.appColors.backgroundWhite,
  114. actions: [
  115. state.currentPageViewIdx == 1? MyAssetImage(
  116. isCollection.value? Assets.propertyCollectionActive: Assets.propertyCollection,
  117. width: 22.5,
  118. height: 21,
  119. ).onTap((){
  120. isCollection.value = !isCollection.value;
  121. _vm.handlerCollectionFilter(context,isCollection.value);
  122. }):Container(),
  123. const SizedBox(width: 20),
  124. ],
  125. ),
  126. body: AutoTabsRouter.pageView(
  127. key: tabsRouterKey,
  128. routes: const [
  129. PropertyIoanPageRoute(),
  130. PropertyNewsPageRoute(),
  131. PropertySalePageRoute(),
  132. PropertyRentPageRoute(),
  133. ],
  134. builder: (context, child, pageController) {
  135. final tabsRouter = AutoTabsRouter.of(context);
  136. return Column(
  137. children: [
  138. _buildTopSection(context, ref, _vm, tabsRouter),
  139. Expanded(
  140. child: child,
  141. ),
  142. ],
  143. );
  144. },
  145. )
  146. );
  147. }
  148. }