| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:get/get.dart';
- import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
- import '../../../../config/translations/strings_enum.dart';
- import '../../../base/base_view.dart';
- import '../../../widgets/ix_app_bar.dart';
- import '../controllers/node_controller.dart';
- import '../widgets/node_list.dart';
- class NodeView extends BaseView<NodeController> {
- const NodeView({super.key});
- @override
- PreferredSizeWidget? get appBar => IXAppBar(title: Strings.selectServer.tr);
- @override
- Widget buildContent(BuildContext context) {
- final tabCount = controller.tabTextList.length;
- if (tabCount == 0) {
- return Center(child: Text(Strings.noData.tr));
- }
- return DefaultTabController(
- length: tabCount,
- initialIndex: controller.currentTabIndex, // 恢复上次的 Tab 位置
- child: Column(
- children: [
- _buildTabs(),
- Expanded(child: _buildTabBarView()),
- ],
- ),
- );
- }
- Widget _buildTabs() {
- return TabBar(
- splashFactory: NoSplash.splashFactory,
- overlayColor: WidgetStateProperty.all(Colors.transparent),
- isScrollable: true,
- tabAlignment: TabAlignment.start,
- dividerColor: Get.reactiveTheme.dividerColor,
- indicatorSize: TabBarIndicatorSize.label,
- indicatorColor: Colors.transparent,
- // indicator: BoxDecoration(
- // color: Get.reactiveTheme.primaryColor,
- // borderRadius: BorderRadius.circular(8.r),
- // ),
- // indicatorWeight: 2,
- labelColor: Colors.white,
- unselectedLabelColor: Get.reactiveTheme.hintColor,
- labelStyle: TextStyle(
- fontSize: 14.sp,
- fontWeight: FontWeight.w400,
- fontFamily: 'FiraSans',
- ),
- unselectedLabelStyle: TextStyle(
- fontSize: 14.sp,
- fontWeight: FontWeight.w400,
- fontFamily: 'FiraSans',
- ),
- padding: EdgeInsets.symmetric(horizontal: 7.w, vertical: 10.w),
- labelPadding: EdgeInsets.symmetric(horizontal: 7.w, vertical: 0.w),
- // 监听 Tab 切换,保存当前索引
- onTap: (index) {
- controller.setTabSelected(index);
- },
- tabs: controller.tabTextList.map((e) {
- return Container(
- padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.w),
- decoration: BoxDecoration(
- color:
- controller.currentTabIndex == controller.tabTextList.indexOf(e)
- ? Get.reactiveTheme.primaryColor
- : Get.reactiveTheme.cardColor,
- borderRadius: BorderRadius.circular(8.r),
- ),
- child: Row(
- children: [
- Icon(
- controller.getTabIcon(controller.tabTextList.indexOf(e)),
- size: 14.w,
- ),
- 4.horizontalSpace,
- Text(e),
- ],
- ),
- );
- }).toList(),
- );
- }
- Widget _buildTabBarView() {
- return TabBarView(
- physics: const NeverScrollableScrollPhysics(), // 禁用左右滑动
- children: List.generate(
- controller.tabTextList.length,
- (index) => NodeList(tabIndex: index),
- ),
- );
- }
- }
|