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.

74 lines
2.4 KiB

3 years ago
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/category_select_list.dart';
import 'package:huixiang/retrofit/data/goods_category.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<CategorySelectList> classSelectList;
final Function notifyClassSelectList;
ClassTitleTab(this.classSelectList,this.notifyClassSelectList);
@override
State<StatefulWidget> createState() {
return _ClassTitleTab();
}
}
class _ClassTitleTab extends State<ClassTitleTab>
with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin {
3 years ago
TabController tabController;
@override
void initState() {
super.initState();
if (widget.classSelectList != null && widget.classSelectList.length > 0)
tabController = TabController(length: widget.classSelectList.length, vsync: this );
}
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.centerLeft,
child: DefaultTabController(
length:widget.classSelectList == null
? 0
: widget.classSelectList.length,
child: TabBar(
isScrollable: true,
//可滚动
indicatorColor: Color(0xff39B54A),
labelColor: Color(0xff32A060),
labelStyle: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.bold,
),
unselectedLabelStyle: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
),
controller: tabController,
//未选中文字颜色
unselectedLabelColor: Color(0xff4D4D4D),
indicatorSize: TabBarIndicatorSize.label,
onTap: (index){
widget.notifyClassSelectList(index);
},
//指示器与文字等宽
tabs:widget.classSelectList == null
? []
: widget.classSelectList
.map((e) => MyTab(text: e.name))
.toList(),
),
),
);
}
@override
bool get wantKeepAlive => true;
3 years ago
}