如何解决Flutter 底部导航栏:第一项比其余项大
[这里是截图:https://i.stack.imgur.com/V2BnH.png][1]
我不是 Flutter 专家,所以我用 5 个图标创建了这个底部导航栏。问题是,不知何故,最左侧的第一个图标比其他图标稍大。特别是最左侧第一个图标下方的文本'Start'比其他图标大一点。我真的无法解释为什么? 到目前为止我尝试过的是添加 BottomNavigationBarType.fixed 但这并没有解决问题.. 我能做什么?非常感谢!!
HomePage({Key key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
PageController _pageController = PageController();
List<Widget> _screens = [
WallBoxPage(),RechnerPage(),StartPage(),MapsPage(),TimerPage()
];
int _selectedindex = 0;
void _onPageChanged(int index) {
setState(
() {
_selectedindex = index;
},);
}
void _onItemTapped(int selectedindex) {
_pageController.jumpToPage(selectedindex);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView(
controller: _pageController,children: _screens,onPageChanged: _onPageChanged,physics: NeverScrollableScrollPhysics(),),bottomNavigationBar: BottomNavigationBar(
//showUnselectedLabels: false,//showSelectedLabels: false,type: BottomNavigationBarType
.fixed,//das muss dazu,damit mehr als 5 Items möglich.
backgroundColor: Color(0xffECECEB),onTap: _onItemTapped,//unselectedFontSize: 12,//selectedFontSize: 12,items: [
BottomNavigationBarItem(
icon: Icon(Icons.home,color: _selectedindex == 0
? Color(0xffF6BE03)
: Color(0xffB4B4B3),size: 25),title: Text(
'Start',style: TextStyle(
color: _selectedindex == 0
? Color(0xffF6BE03)
: Color(0xffB4B4B3),fontSize: 11),BottomNavigationBarItem(
icon: Icon(Icons.directions_car_rounded,color:
_selectedindex == 1 ? Color(0xffF6BE03) : Color(0xffB4B4B3),title: Text(
'Portal',style: TextStyle(
color: _selectedindex == 1
? Color(0xffF6BE03)
: Color(0xffB4B4B3),BottomNavigationBarItem(
icon: Icon(Icons.euro_rounded,color:
_selectedindex == 2 ? Color(0xffF6BE03) : Color(0xffB4B4B3),title: Text(
'Förderungen',style: TextStyle(
color: _selectedindex == 2
? Color(0xffF6BE03)
: Color(0xffB4B4B3),BottomNavigationBarItem(
icon: Icon(Icons.map,color:
_selectedindex == 3 ? Color(0xffF6BE03) : Color(0xffB4B4B3),title: Text(
'Karte',style: TextStyle(
color: _selectedindex == 3
? Color(0xffF6BE03)
: Color(0xffB4B4B3),BottomNavigationBarItem(
icon: Icon(Icons.timer,color:
_selectedindex == 4 ? Color(0xffF6BE03) : Color(0xffB4B4B3),title: Text(
'Ladezeit',style: TextStyle(
color: _selectedindex == 4
? Color(0xffF6BE03)
: Color(0xffB4B4B3),],);
}
}```
[1]: https://i.stack.imgur.com/V2BnH.png
解决方法
在 BottonNavigationBar 中使用 unselectedFontSize,selectedFontSize,currentIndex: _selectedIndex
得到你期望的结果
示例
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。