node_view.dart 2.6 KB

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