node_view.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
  5. import '../../../base/base_view.dart';
  6. import '../../../widgets/ix_app_bar.dart';
  7. import '../controllers/node_controller.dart';
  8. import '../widgets/node_list.dart';
  9. class NodeView extends BaseView<NodeController> {
  10. const NodeView({super.key});
  11. @override
  12. Widget buildContent(BuildContext context) {
  13. final tabCount = controller.tabTextList.length;
  14. if (tabCount == 0) {
  15. return const Center(child: Text('暂无数据'));
  16. }
  17. return DefaultTabController(
  18. length: tabCount,
  19. initialIndex: controller.currentTabIndex, // 恢复上次的 Tab 位置
  20. child: Column(
  21. children: [
  22. IXAppBar(title: 'Select Server'),
  23. _buildTabs(),
  24. Divider(color: Get.reactiveTheme.dividerColor, height: 0.5),
  25. Expanded(child: _buildTabBarView()),
  26. ],
  27. ),
  28. );
  29. }
  30. Widget _buildTabs() {
  31. return TabBar(
  32. splashFactory: NoSplash.splashFactory,
  33. overlayColor: WidgetStateProperty.all(Colors.transparent),
  34. isScrollable: true,
  35. tabAlignment: TabAlignment.start,
  36. dividerColor: Colors.transparent,
  37. indicatorSize: TabBarIndicatorSize.tab,
  38. indicatorColor: Get.reactiveTheme.primaryColor,
  39. indicator: BoxDecoration(
  40. color: Get.reactiveTheme.primaryColor,
  41. borderRadius: BorderRadius.circular(8.r),
  42. ),
  43. // indicatorWeight: 2,
  44. labelColor: Get.reactiveTheme.textTheme.bodyLarge!.color,
  45. unselectedLabelColor: Get.reactiveTheme.hintColor,
  46. labelStyle: TextStyle(
  47. fontSize: 14.sp,
  48. fontWeight: FontWeight.w400,
  49. fontFamily: 'FiraSans',
  50. ),
  51. unselectedLabelStyle: TextStyle(
  52. fontSize: 14.sp,
  53. fontWeight: FontWeight.w400,
  54. fontFamily: 'FiraSans',
  55. ),
  56. padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 10.w),
  57. labelPadding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.w),
  58. // 监听 Tab 切换,保存当前索引
  59. onTap: (index) {
  60. controller.currentTabIndex = index;
  61. },
  62. tabs: controller.tabTextList.map((e) {
  63. return Row(
  64. children: [
  65. Icon(Icons.terminal, size: 14.w),
  66. 4.horizontalSpace,
  67. Text(e),
  68. ],
  69. );
  70. }).toList(),
  71. );
  72. }
  73. Widget _buildTabBarView() {
  74. return TabBarView(
  75. children: List.generate(
  76. controller.tabTextList.length,
  77. (index) => NodeList(tabIndex: index),
  78. ),
  79. );
  80. }
  81. }