property_page.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. MyTextView(
  54. item['title'],
  55. maxLines: 1, // 设置最大行数为2
  56. isTextEllipsis: true, // 超出部分用省略号表示
  57. fontSize: 13,
  58. textColor: curIdx == index ? ColorUtils.string2Color('#4161D0'):Colors.black,
  59. isFontMedium: true,
  60. ),
  61. ],
  62. ),
  63. ).marginOnly(left: 18, right: 18, top: 10, bottom: 10);
  64. }),
  65. ),
  66. ),
  67. );
  68. }
  69. @override
  70. Widget build(BuildContext context, WidgetRef ref) {
  71. final _vm = ref.read(propertyVmProvider.notifier);
  72. return Scaffold(
  73. appBar: MyAppBar.appBar(
  74. context,
  75. "Property",
  76. backgroundColor: context.appColors.whiteBG,
  77. ),
  78. body: Row(
  79. children: [
  80. Expanded(
  81. child: Column(
  82. children: [
  83. _buildTopSection(context, ref, _vm),
  84. const Expanded(
  85. child: AutoRouter(),
  86. )
  87. ],
  88. ),
  89. )
  90. ],
  91. )
  92. );
  93. }
  94. }