property_page.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 '../../../router/page/property_page_router.dart';
  11. import '../vm/property_vm.dart';
  12. @RoutePage()
  13. class PropertyPage extends HookConsumerWidget {
  14. const PropertyPage({Key? key}) : super(key: key);
  15. //启动当前页面
  16. static void startInstance({BuildContext? context}) {
  17. if (context != null) {
  18. context.router.push(const PropertyPageRoute());
  19. } else {
  20. appRouter.push(const PropertyPageRoute());
  21. }
  22. }
  23. // 顶部tab 切换
  24. Widget _buildTopSection(BuildContext context, WidgetRef ref, _vm) {
  25. final topSectionsData = _vm.topSectionsData;
  26. // 监听 curIdx 的变化
  27. final curIdx = ref.watch(propertyVmProvider.select((value) => value.curIdx));
  28. return Container(
  29. color: Colors.white,
  30. child: Center(
  31. child: Row(
  32. mainAxisAlignment: MainAxisAlignment.center,
  33. crossAxisAlignment: CrossAxisAlignment.center,
  34. children: List.generate(topSectionsData.length, (index) {
  35. final item = topSectionsData[index];
  36. return Flexible(
  37. flex: 1,
  38. child: Column(
  39. children: [
  40. MyAssetImage(
  41. item['icon'],
  42. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  43. height: 70,
  44. ).onTap(
  45. () {
  46. _vm.switchPage(index, context);
  47. },
  48. type: ClickType.throttle,
  49. ),
  50. SizedBox.fromSize(size: const Size(0, 9)),
  51. Text(
  52. item['title'],
  53. maxLines: 1, // 设置最大行数为2
  54. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  55. style: TextStyle(
  56. fontSize: 13.0,
  57. color: curIdx == index ? ColorUtils.string2Color('#4161D0'):Colors.black,
  58. fontWeight: FontWeight.w500
  59. ), // 设置字体大小
  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 DefaultTabController(
  73. length: 4,
  74. child: Scaffold(
  75. appBar: AppBar(
  76. title: const Text("Property"),
  77. bottomOpacity: 0.0, // 取消下横线
  78. titleTextStyle: const TextStyle(color: Colors.black),
  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. }