property_page.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import 'package:cs_resources/theme/app_colors_theme.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:auto_route/auto_route.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 '../../../router/page/property_page_router.dart';
  13. import '../vm/property_vm.dart';
  14. @RoutePage()
  15. class PropertyPage extends HookConsumerWidget {
  16. const PropertyPage({Key? key}) : super(key: key);
  17. //启动当前页面
  18. static void startInstance({BuildContext? context}) {
  19. if (context != null) {
  20. context.router.push(const PropertyPageRoute());
  21. } else {
  22. appRouter.push(const PropertyPageRoute());
  23. }
  24. }
  25. // 顶部tab 切换
  26. Widget _buildTopSection(BuildContext context, WidgetRef ref, _vm) {
  27. final topSectionsData = _vm.topSectionsData;
  28. // 监听 curIdx 的变化
  29. final curIdx = ref.watch(propertyVmProvider.select((value) => value.curIdx));
  30. return Container(
  31. color: Colors.white,
  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: 13.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.read(propertyVmProvider.notifier);
  74. return Scaffold(
  75. appBar: MyAppBar.appBar(
  76. context,
  77. "Property",
  78. backgroundColor: context.appColors.whiteBG,
  79. ),
  80. body: Row(
  81. children: [
  82. Expanded(
  83. child: Column(
  84. children: [
  85. _buildTopSection(context, ref, _vm),
  86. const Expanded(
  87. child: AutoRouter(),
  88. )
  89. ],
  90. ),
  91. )
  92. ],
  93. )
  94. );
  95. }
  96. }