You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.1 KiB
72 lines
2.1 KiB
import 'package:flutter/material.dart'; |
|
import 'package:huixiang/data/category_select.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:huixiang/view_widget/my_tab.dart'; |
|
|
|
class ClassTitleTab extends StatefulWidget { |
|
final List<CategorySelect> classSelectList; |
|
final Function notifyClassSelectList; |
|
|
|
ClassTitleTab(this.classSelectList,this.notifyClassSelectList); |
|
|
|
@override |
|
State<StatefulWidget> createState() { |
|
return _ClassTitleTab(); |
|
} |
|
} |
|
|
|
class _ClassTitleTab extends State<ClassTitleTab> with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin { |
|
TabController? tabController; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
if (widget.classSelectList.length > 0) |
|
tabController = TabController(length: widget.classSelectList.length, vsync: this ); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
super.build(context); |
|
return Container( |
|
alignment: Alignment.centerLeft, |
|
child: DefaultTabController( |
|
length: widget.classSelectList.length, |
|
child: TabBar( |
|
isScrollable: true, |
|
//可滚动 |
|
indicatorColor: Color(0xff39B54A), |
|
labelColor: Color(0xff32A060), |
|
labelStyle: TextStyle( |
|
fontSize: 14.sp, |
|
fontWeight: FontWeight.bold, |
|
), |
|
tabAlignment: TabAlignment.start, |
|
padding: EdgeInsets.symmetric( |
|
horizontal: 5.w, |
|
), |
|
dividerHeight: 0, |
|
dividerColor: Colors.transparent, |
|
unselectedLabelStyle: TextStyle( |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
controller: tabController, |
|
//未选中文字颜色 |
|
unselectedLabelColor: Color(0xff4D4D4D), |
|
indicatorSize: TabBarIndicatorSize.label, |
|
onTap: (index){ |
|
widget.notifyClassSelectList(index); |
|
}, |
|
//指示器与文字等宽 |
|
tabs: widget.classSelectList.map((e) => MyTab(text: "${e.name}")).toList(), |
|
), |
|
), |
|
); |
|
} |
|
|
|
@override |
|
bool get wantKeepAlive => true; |
|
|
|
}
|
|
|