community_page1.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 '../../router/page/community_page_router.dart';
  13. import 'community_vm.dart';
  14. @RoutePage()
  15. class CommunityPage extends HookConsumerWidget {
  16. const CommunityPage({Key? key}) : super(key: key);
  17. //启动当前页面
  18. static void startInstance({BuildContext? context}) {
  19. if (context != null) {
  20. context.router.push(const CommunityPageRoute());
  21. } else {
  22. appRouter.push(const CommunityPageRoute());
  23. }
  24. }
  25. Widget _buildTopSection(BuildContext context, WidgetRef ref, _vm) {
  26. final topSectionsData = _vm.topSectionsData;
  27. // 监听 curIdx 的变化
  28. final curIdx = ref.watch(communityVmProvider.select((value) => value.curIdx));
  29. return Container(
  30. color: Colors.white,
  31. padding: const EdgeInsets.only(top: 30, bottom: 30),
  32. child: Center(
  33. child: Row(
  34. mainAxisAlignment: MainAxisAlignment.center,
  35. crossAxisAlignment: CrossAxisAlignment.center,
  36. children: List.generate(topSectionsData.length, (index) {
  37. final item = topSectionsData[index];
  38. return Flexible(
  39. flex: 1,
  40. child: Column(
  41. children: [
  42. MyAssetImage(
  43. item['icon'],
  44. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  45. height: 70,
  46. ).onTap(
  47. () {
  48. _vm.switchPage(index, context);
  49. },
  50. type: ClickType.throttle,
  51. ),
  52. SizedBox.fromSize(size: const Size(0, 9)),
  53. Text(
  54. item['title'],
  55. maxLines: 1, // 设置最大行数为2
  56. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  57. style: TextStyle(
  58. fontSize: 15.0,
  59. color: curIdx == index ? ColorUtils.string2Color('#4161D0'):Colors.black,
  60. fontWeight: FontWeight.w500
  61. ), // 设置字体大小
  62. ),
  63. ],
  64. ),
  65. ).marginOnly(left: 18, right: 18, top: 10, bottom: 10);
  66. }),
  67. ),
  68. ),
  69. );
  70. }
  71. @override
  72. Widget build(BuildContext context, WidgetRef ref) {
  73. final vm = ref.watch(communityVmProvider.notifier);
  74. return Scaffold(
  75. appBar: MyAppBar.appBar(
  76. context,
  77. "Community",
  78. backgroundColor: context.appColors.whiteBG,
  79. ),
  80. backgroundColor: context.appColors.backgroundDefault,
  81. body: Row(
  82. children: [
  83. Expanded(
  84. child: Column(
  85. children: [
  86. _buildTopSection(context, ref, vm),
  87. const Expanded(
  88. child: AutoRouter(),
  89. )
  90. ],
  91. ),
  92. )
  93. ],
  94. )
  95. );
  96. }
  97. }