为什么点击后底部导航栏项的标签没有变化?



我选择和未选择的BottomNavigationBarItems的标签颜色不会改变。。。我尝试了很多方法,比如

selectedItemColor: Colors.blue,
unselectedItemColor: Colors.black,

unselectedLabelStyle: const TextStyle(color: Colors.grey, fontSize: 14),
selectedLabelStyle: const TextStyle(color: Colors.blue, fontSize: 14),

等等。我做错了什么?这是代码:

class RandomWordsState extends State<RandomWords> {
var _currentIndex = 0;
var _pageList = [HomePage(), RecommendPage(), PersonalPage()];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('APPBAR'),
centerTitle: true,
elevation: 10,
),
//body: this._pageList[this._currentIndex],
body: IndexedStack(index: _currentIndex, children: _pageList,),
bottomNavigationBar: BottomNavigationBar(
selectedItemColor: Colors.blue,
unselectedItemColor: Colors.black,
//unselectedItemColor: Colors.black,
//selectedItemColor: Colors.blue,
//selectedLabelStyle: TextStyle(fontSize: 22),
//selectedItemColor: Colors.red,
//fixedColor: Colors.blue,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(
Icons.home,
//color: _currentIndex == 0 ? Colors.blue : Colors.grey,
),
label: "A",
),
BottomNavigationBarItem(
label: "B",
icon: Icon(
Icons.recommend,
//color: _currentIndex == 1 ? Colors.blue : Colors.grey,
),
),
BottomNavigationBarItem(
icon: Icon(
Icons.person,
//color: _currentIndex == 2 ? Colors.blue : Colors.grey,
),
label: "C",
)
],
onTap: (value){
setState(() {
this._currentIndex = value.toInt();
});
},
// unselectedLabelStyle: const TextStyle(color: Colors.grey, fontSize: 14),
// selectedLabelStyle: const TextStyle(color: Colors.blue, fontSize: 14),
type: BottomNavigationBarType.fixed,
),
);
}
}

或者,另一方面,有什么方法可以更改BottomNavigationBarItem中标签的颜色吗?谢谢

您需要在BottomNavigationBar上提供currentIndex才能看到效果。

bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,

有关底部导航栏的更多信息。

最新更新