node_view.dart 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. Divider(color: Get.reactiveTheme.dividerColor, height: 0.5),
  27. Expanded(child: _buildTabBarView()),
  28. ],
  29. ),
  30. );
  31. }
  32. Widget _buildTabs() {
  33. return TabBar(
  34. splashFactory: NoSplash.splashFactory,
  35. overlayColor: WidgetStateProperty.all(Colors.transparent),
  36. isScrollable: true,
  37. tabAlignment: TabAlignment.start,
  38. dividerColor: Colors.transparent,
  39. indicatorSize: TabBarIndicatorSize.tab,
  40. indicatorColor: Get.reactiveTheme.primaryColor,
  41. indicator: BoxDecoration(
  42. color: Get.reactiveTheme.primaryColor,
  43. borderRadius: BorderRadius.circular(8.r),
  44. ),
  45. // indicatorWeight: 2,
  46. labelColor: Colors.white,
  47. unselectedLabelColor: Get.reactiveTheme.hintColor,
  48. labelStyle: TextStyle(
  49. fontSize: 14.sp,
  50. fontWeight: FontWeight.w400,
  51. fontFamily: 'FiraSans',
  52. ),
  53. unselectedLabelStyle: TextStyle(
  54. fontSize: 14.sp,
  55. fontWeight: FontWeight.w400,
  56. fontFamily: 'FiraSans',
  57. ),
  58. padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 10.w),
  59. labelPadding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.w),
  60. // 监听 Tab 切换,保存当前索引
  61. onTap: (index) {
  62. controller.setTabSelected(index);
  63. },
  64. tabs: controller.tabTextList.map((e) {
  65. return Row(
  66. children: [
  67. Icon(
  68. controller.getTabIcon(controller.tabTextList.indexOf(e)),
  69. size: 14.w,
  70. ),
  71. 4.horizontalSpace,
  72. Text(e),
  73. ],
  74. );
  75. }).toList(),
  76. );
  77. }
  78. Widget _buildTabBarView() {
  79. return TabBarView(
  80. children: List.generate(
  81. controller.tabTextList.length,
  82. (index) => NodeList(tabIndex: index),
  83. ),
  84. );
  85. }
  86. }