community_page.dart 4.9 KB

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