property_page.dart 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/log_utils.dart';
  6. import 'package:widgets/my_load_image.dart';
  7. import 'package:widgets/ext/ex_widget.dart';
  8. import '../../../router/page/property_page_router.dart';
  9. import '../vm/property_vm.dart';
  10. @RoutePage()
  11. class PropertyPage extends HookConsumerWidget {
  12. const PropertyPage({Key? key}) : super(key: key);
  13. //启动当前页面
  14. static void startInstance({BuildContext? context}) {
  15. if (context != null) {
  16. context.router.push(const PropertyPageRoute());
  17. } else {
  18. appRouter.push(const PropertyPageRoute());
  19. }
  20. }
  21. // 顶部tab 切换
  22. Widget _buildTopSection(BuildContext context, WidgetRef ref, _vm) {
  23. final topSectionsData = _vm.topSectionsData;
  24. return Container(
  25. color: Colors.white,
  26. child: Center(
  27. child: Row(
  28. mainAxisAlignment: MainAxisAlignment.center,
  29. crossAxisAlignment: CrossAxisAlignment.center,
  30. children: List.generate(topSectionsData.length, (index) {
  31. final item = topSectionsData[index];
  32. return Flexible(
  33. flex: 1,
  34. child: Column(
  35. children: [
  36. MyAssetImage(
  37. item['icon'],
  38. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  39. height: 70,
  40. ).onTap(
  41. () {
  42. _vm.switchPage(index, context);
  43. },
  44. type: ClickType.throttle,
  45. ),
  46. SizedBox.fromSize(size: const Size(0, 9)),
  47. Text(
  48. item['title'],
  49. maxLines: 1, // 设置最大行数为2
  50. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  51. style: const TextStyle(fontSize: 13.0, color: Colors.black, fontWeight: FontWeight.w500), // 设置字体大小
  52. ),
  53. ],
  54. ),
  55. ).marginOnly(left: 18, right: 18, top: 10, bottom: 10);
  56. }),
  57. ),
  58. ),
  59. );
  60. }
  61. @override
  62. Widget build(BuildContext context, WidgetRef ref) {
  63. final _vm = ref.read(propertyVmProvider.notifier);
  64. return DefaultTabController(
  65. length: 4,
  66. child: Scaffold(
  67. appBar: AppBar(
  68. title: const Text("Property"),
  69. bottomOpacity: 0.0, // 取消下横线
  70. titleTextStyle: const TextStyle(color: Colors.black),
  71. ),
  72. body: Row(
  73. children: [
  74. Expanded(
  75. child: Column(
  76. children: [
  77. _buildTopSection(context, ref, _vm),
  78. const Expanded(
  79. child: AutoRouter(),
  80. )
  81. ],
  82. ),
  83. )
  84. ],
  85. )),
  86. );
  87. }
  88. }