node_view.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 '../../../../config/translations/strings_enum.dart';
  6. import '../../../base/base_view.dart';
  7. import '../../../widgets/ix_app_bar.dart';
  8. import '../controllers/node_controller.dart';
  9. import '../widgets/node_list.dart';
  10. class NodeView extends BaseView<NodeController> {
  11. const NodeView({super.key});
  12. @override
  13. PreferredSizeWidget? get appBar => IXAppBar(title: Strings.selectServer.tr);
  14. @override
  15. Widget buildContent(BuildContext context) {
  16. final tabCount = controller.tabTextList.length;
  17. if (tabCount == 0) {
  18. return Center(child: Text(Strings.noData.tr));
  19. }
  20. return DefaultTabController(
  21. length: tabCount,
  22. initialIndex: controller.currentTabIndex, // 恢复上次的 Tab 位置
  23. child: Column(
  24. children: [
  25. _buildTabs(),
  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: Get.reactiveTheme.dividerColor,
  38. indicatorSize: TabBarIndicatorSize.label,
  39. indicatorColor: Colors.transparent,
  40. // indicator: BoxDecoration(
  41. // color: Get.reactiveTheme.primaryColor,
  42. // borderRadius: BorderRadius.circular(8.r),
  43. // ),
  44. // indicatorWeight: 2,
  45. labelColor: Colors.white,
  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: 7.w, vertical: 10.w),
  58. labelPadding: EdgeInsets.symmetric(horizontal: 7.w, vertical: 0.w),
  59. // 监听 Tab 切换,保存当前索引
  60. onTap: (index) {
  61. controller.setTabSelected(index);
  62. },
  63. tabs: controller.tabTextList.map((e) {
  64. return Container(
  65. padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.w),
  66. decoration: BoxDecoration(
  67. color:
  68. controller.currentTabIndex == controller.tabTextList.indexOf(e)
  69. ? Get.reactiveTheme.primaryColor
  70. : Get.reactiveTheme.cardColor,
  71. borderRadius: BorderRadius.circular(8.r),
  72. ),
  73. child: Row(
  74. children: [
  75. Icon(
  76. controller.getTabIcon(controller.tabTextList.indexOf(e)),
  77. size: 14.w,
  78. ),
  79. 4.horizontalSpace,
  80. Text(e),
  81. ],
  82. ),
  83. );
  84. }).toList(),
  85. );
  86. }
  87. Widget _buildTabBarView() {
  88. return TabBarView(
  89. physics: const NeverScrollableScrollPhysics(), // 禁用左右滑动
  90. children: List.generate(
  91. controller.tabTextList.length,
  92. (index) => NodeList(tabIndex: index),
  93. ),
  94. );
  95. }
  96. }