community_page.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import 'package:flutter/material.dart';
  2. import 'package:auto_route/auto_route.dart';
  3. import 'package:flutter_hooks/flutter_hooks.dart';
  4. import 'package:hooks_riverpod/hooks_riverpod.dart';
  5. import 'package:router/ext/auto_router_extensions.dart';
  6. import 'package:shared/utils/color_utils.dart';
  7. import 'package:shared/utils/log_utils.dart';
  8. import 'package:widgets/my_load_image.dart';
  9. import 'package:widgets/ext/ex_widget.dart';
  10. import 'package:widgets/my_text_view.dart';
  11. import 'package:widgets/my_appbar.dart';
  12. import 'package:cs_resources/theme/app_colors_theme.dart';
  13. import 'package:widgets/widget_export.dart';
  14. import '../../router/page/community_page_router.dart';
  15. import 'community_vm.dart';
  16. @RoutePage()
  17. class CommunityPage extends HookConsumerWidget {
  18. const CommunityPage({Key? key}) : super(key: key);
  19. //启动当前页面
  20. static void startInstance({BuildContext? context}) {
  21. if (context != null) {
  22. context.router.push(const CommunityPageRoute());
  23. } else {
  24. appRouter.push(const CommunityPageRoute());
  25. }
  26. }
  27. Widget _buildTopSection(BuildContext context, WidgetRef ref, vm, tabsRouter) {
  28. final topSectionsData = vm.topSectionsData;
  29. final currentTabIdx = tabsRouter.activeIndex;
  30. // 监听 curIdx 的变化
  31. // final curIdx = ref.watch(communityVmProvider.select((value) => value.curIdx));
  32. return Container(
  33. color: Colors.white,
  34. padding: const EdgeInsets.only(top: 30, bottom: 30),
  35. child: Center(
  36. child: Row(
  37. mainAxisAlignment: MainAxisAlignment.center,
  38. crossAxisAlignment: CrossAxisAlignment.center,
  39. children: List.generate(topSectionsData.length, (index) {
  40. final item = topSectionsData[index];
  41. return Flexible(
  42. flex: 1,
  43. child: Column(
  44. children: [
  45. Container(
  46. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  47. height: 70,
  48. decoration: BoxDecoration(
  49. // color: currentTabIdx == index ? ColorUtils.string2Color('#E6F2FF') : Colors.white,
  50. shape: BoxShape.circle, // 设置为圆形
  51. boxShadow: tabsRouter.activeIndex == index ? [
  52. BoxShadow(
  53. color: context.appColors.tabLightBlueShadow, // 设置阴影颜色
  54. blurRadius: 5, // 设置模糊半径
  55. spreadRadius: 0.05, // 控制阴影扩散
  56. offset: const Offset(0, 4), // 设置阴影偏移量
  57. ),
  58. ] : [],// 未选中时无阴影,
  59. ),
  60. child: MyAssetImage(
  61. item['icon'],
  62. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  63. height: 70,
  64. ).onTap(() {
  65. tabsRouter.setActiveIndex(index);
  66. },
  67. type: ClickType.throttle,
  68. ),
  69. ),
  70. SizedBox.fromSize(size: const Size(0, 9)),
  71. Text(
  72. item['title'],
  73. maxLines: 1, // 设置最大行数为2
  74. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  75. style: TextStyle(
  76. fontSize: 15.0,
  77. color: currentTabIdx == index ? ColorUtils.string2Color('#4161D0'):Colors.black,
  78. fontWeight: FontWeight.w500
  79. ), // 设置字体大小
  80. ),
  81. ],
  82. ),
  83. ).marginOnly(left: 18, right: 18, top: 10, bottom: 10);
  84. }),
  85. ),
  86. ),
  87. );
  88. }
  89. @override
  90. Widget build(BuildContext context, WidgetRef ref) {
  91. final vm = ref.read(communityVmProvider.notifier);
  92. return Scaffold(
  93. appBar: MyAppBar.appBar(
  94. context,
  95. "Community",
  96. backgroundColor: context.appColors.whiteBG,
  97. ),
  98. backgroundColor: context.appColors.backgroundDefault,
  99. body: AutoTabsRouter.pageView(
  100. routes: const [
  101. NewsfeedPageRoute(),
  102. GaragesalePageRoute(),
  103. ],
  104. builder: (context, child, pageController) {
  105. print("pageView child: $child, $pageController");
  106. final tabsRouter = AutoTabsRouter.of(context);
  107. // 设置当前的 useTag 0 newsFeed 1 garageSale
  108. vm.setCurrentUseTag(tabsRouter.activeIndex);
  109. return Column(
  110. children: [
  111. _buildTopSection(context, ref, vm, tabsRouter),
  112. Expanded(
  113. child: child,
  114. ),
  115. ],
  116. );
  117. },
  118. ),
  119. );
  120. }
  121. }