class Tabs extends StatefulWidget {
const Tabs({super.key});
@override
State<Tabs> createState() => _TabsState();
}
class _TabsState extends State<Tabs> {
int _currentIndex = homeG.tabsCurrentIndex ?? 0;
final List<Widget> _pages = homeG.isJobFair == false ||
homeG.isJobFair == null
? [HomePage(), ClockInPage(), MessagePage(), UserPage()]
: [HomePage(), JobFairPage(), ClockInPage(), MessagePage(), UserPage()];
@override
Widget build(BuildContext context) {
return Scaffold(
body: _pages[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
iconSize: 20,
selectedFontSize: 10,
unselectedFontSize: 10,
selectedLabelStyle: TextStyle(height: 2.0), // 调整行高
unselectedLabelStyle: TextStyle(height: 2.0), // 调整行高
fixedColor: AppColors.firstdaryColor,
currentIndex: _currentIndex,
type: BottomNavigationBarType.fixed,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
items: [
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage(
_currentIndex == 0
? 'images/tabBar/home-select.png'
: 'images/tabBar/home.png',
),
size: 20,
color: _currentIndex == 0
? AppColors.firstdaryColor
: Color(0xFFC1C8D0),
),
label: "首页",
),
if (homeG.isJobFair == true)
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage(
_currentIndex == 1
? 'images/tabBar/jobfair-select.png'
: 'images/tabBar/jobfair.png',
),
size: 20,
color: _currentIndex == 1
? AppColors.firstdaryColor
: Color(0xFFC1C8D0),
),
label: "招聘会",
),
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage(
homeG.isJobFair == false
? _currentIndex == 1
? 'images/tabBar/clock-select.png'
: 'images/tabBar/clock.png'
: _currentIndex == 2
? 'images/tabBar/clock-select.png'
: 'images/tabBar/clock.png',
),
size: 20,
color: homeG.isJobFair == false
? _currentIndex == 1
? AppColors.firstdaryColor
: Color(0xFFC1C8D0)
: _currentIndex == 2
? AppColors.firstdaryColor
: Color(0xFFC1C8D0),
),
label: "打卡",
),
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage(
homeG.isJobFair == false
? _currentIndex == 2
? 'images/tabBar/message-select.png'
: 'images/tabBar/message.png'
: _currentIndex == 3
? 'images/tabBar/message-select.png'
: 'images/tabBar/message.png',
),
size: 20,
color: homeG.isJobFair == false
? _currentIndex == 2
? AppColors.firstdaryColor
: Color(0xFFC1C8D0)
: _currentIndex == 3
? AppColors.firstdaryColor
: Color(0xFFC1C8D0),
),
label: "消息",
),
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage(
homeG.isJobFair == false
? _currentIndex == 3
? 'images/tabBar/mine-selset.png'
: 'images/tabBar/mine.png'
: _currentIndex == 4
? 'images/tabBar/mine-selset.png'
: 'images/tabBar/mine.png',
),
size: 20,
color: homeG.isJobFair == false
? _currentIndex == 3
? AppColors.firstdaryColor
: Color(0xFFC1C8D0)
: _currentIndex == 4
? AppColors.firstdaryColor
: Color(0xFFC1C8D0),
),
label: "我的",
),
],
)
);
}
}
以上代码存在的问题,设置的颜色会覆盖图片原有的颜色