2024-07-26 09:21:22 +08:00

111 lines
2.8 KiB
Dart
Executable File

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../../../../app_settings/app_colors.dart';
import '../../../../../../tools/CustomUnderlineTabIndicator.dart';
import '../massSendElectronicKey_page.dart';
class MassSendElectronicKeyManageTabbar extends StatefulWidget {
MassSendElectronicKeyManageTabbar({required this.initialIndex, Key? key})
: super(key: key);
int initialIndex = 1;
@override
State<MassSendElectronicKeyManageTabbar> createState() =>
_MassSendElectronicKeyManageTabbarState();
}
class _MassSendElectronicKeyManageTabbarState
extends State<MassSendElectronicKeyManageTabbar>
with SingleTickerProviderStateMixin {
late TabController _tabController;
final List<ItemView> _itemTabs = <ItemView>[
ItemView(title: '限时'.tr, type: '0'),
ItemView(title: '永久'.tr, type: '1'),
ItemView(title: '循环'.tr, type: '2'),
];
@override
void initState() {
super.initState();
_tabController = TabController(
vsync: this,
length: _itemTabs.length,
initialIndex: widget.initialIndex);
}
@override
Widget build(BuildContext context) {
return Expanded(
child: Column(
children: <Widget>[
_tabBar(),
_pageWidget(),
],
));
}
TabBar _tabBar() {
return TabBar(
controller: _tabController,
tabs: _itemTabs.map(_tab).toList(),
isScrollable: true,
indicatorColor: Colors.red,
unselectedLabelColor: Colors.black,
unselectedLabelStyle: TextStyle(
color: AppColors.mainColor,
fontSize: 28.sp,
),
automaticIndicatorColorAdjustment: true,
labelColor: AppColors.mainColor,
labelStyle: TextStyle(
color: AppColors.mainColor,
fontSize: 32.sp,
fontWeight: FontWeight.w600),
indicator: CustomUnderlineTabIndicator(
borderSide: BorderSide(color: AppColors.mainColor, width: 4.w),
strokeCap: StrokeCap.round,
width: 30.w),
);
}
Tab _tab(ItemView item) {
return Tab(
// text: item.title,
child: Container(
width: 1.sw / 8,
margin: EdgeInsets.all(10.w),
// color: Colors.red,
child: Text(
item.title,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 24.sp),
),
),
);
}
Widget _pageWidget() {
return Expanded(
child: TabBarView(
controller: _tabController,
children: _itemTabs
.map((ItemView item) => MassSendElectronicKeyPage(
type: item.type,
))
.toList(),
),
);
}
}
class ItemView {
const ItemView({required this.title, required this.type});
final String title;
final String type;
}