flutter - unselectedLabelstyle 在 Flutter 中不起作用
问题描述
为什么我的对我unselectedLabelStyle
不起作用?在这个 unselectedLabelStyle 中使用 textStyle 属性保存我的更改后,我什么都不会改变:/
class _NavBarState extends State<NavBar> {
int _selectedPage = 0;
PageController pageController = PageController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView(
controller: pageController,
children: <Widget>[
HomeScreen(),
MapScreen(),
SearchScreen(),
AccountScreen(),
],
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: _selectedPage,
backgroundColor: Colors.white,
selectedIconTheme: IconThemeData(color: Colors.black, size: 32),
// selectedLabelStyle: TextStyle(fontWeight: FontWeight.bold),
unselectedIconTheme: IconThemeData(size: 26, color: Colors.grey.shade300),
unselectedLabelStyle: TextStyle(color: Colors.grey.shade300),//HEEEEEERRRRRRRRREEEEEE
onTap: (int index) {
setState(() {
_selectedPage = index;
});
pageController.animateToPage(
index,
duration: Duration(milliseconds: 500),
curve:
Curves.easeInOutExpo,
);
},
items: [
BottomNavigationBarItem(
icon: Icon(
Icons.home,
),
title: Text('Główna', style: TextStyle(color: Colors.black))),
BottomNavigationBarItem(
icon: Icon(
Icons.location_on,
),
title: Text('Mapa', style: TextStyle(color: Colors.black))),
BottomNavigationBarItem(
icon: Icon(
Icons.search,
),
title: Text('Szukaj', style: TextStyle(color: Colors.black))),
BottomNavigationBarItem(
icon: Icon(
Icons.person,
),
title: Text('Konto', style: TextStyle(color: Colors.black)),
),
],
),
);
}
@override
void dispose() {
pageController.dispose();
super.dispose();
}
}
解决方案
您通过直接在标题中提供标题样式来重叠 textStyle,此外,您可以使用unselectedItemColor属性来更改未选择项目的颜色。
unselectedItemColor: Colors.grey,
更改标题
title: Text('Główna', style: TextStyle(color: Colors.black))),
至:
title: Text('Główna')),
此外,我认为你应该在flutter sdk中提交错误,因为它没有像你提到的那样工作。
/// If [selectedLabelStyle.color] and [unselectedLabelStyle.color] values
/// are non-null, they will be used instead of [selectedItemColor] and
/// [unselectedItemColor].
根据以下文档注释,如果您指定 unselectedLabelStyle 的颜色,那么它应该使用该颜色但它没有使用它。
推荐阅读
- javascript - 分屏中的居中和图像大小
- javascript - 我应该一直在回报一个承诺吗?
- javascript - Javascript中关于动态加载路径的字符串混淆
- python-3.x - python 代码 number_list = [1, 239, 949, 0, 84, 0, 1] 输出:True number_list = [1, 239, 949, 0, 84, 0, 13] 输出:False
- python - 如何
使用 BeautifulSoup 分割段落? - python - 即使文件仍然打开,np.savetxt 也不会附加
- qt - 如何确定 QtWebEngine 在运行时在 Qt 5 中使用哪个铬版本?
- java - 使用 MockitoJUnitRunner 运行测试失败验证断言
- node.js - 打字稿本地文件类'找不到模块'
- sql - SSRS(报表生成器)对一行进行排序