property_page.dart 5.1 KB

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