property_page.dart 5.6 KB

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