flutter - BottomNavigationBar 颜色错误更改
问题描述
我有一个有颜色的底部导航栏。当我单击最后一个按钮时,颜色变为白色......
最后一个按钮显示一些我可以刷的卡。为此,我在这里使用代码:https ://github.com/devefy/Flutter-Story-App-UI
我试图用其他东西改变 return container() ,但没有什么是有益的。
这是我的代码
void _onItemTapped(int index) {
setState(() {
if (edifice != null) _selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.unEdifice.vocable),
backgroundColor: color_edifices,
),
body: Center(
child: edifice == null
? CircularProgressIndicator()
: _selectedIndex == 5
? SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
CardScrollWidget(currentPage),
Positioned.fill(
child: PageView.builder(
itemCount: edifice.commentaires.length,
controller: controller,
reverse: true,
itemBuilder: (context, index) {
return Container(
);
},
),
)
],
),
],
),
)
: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
backgroundColor: color_edifices,
icon: Icon(GaeoIcons.church, color: Colors.white),
title: Text('Edifice', style: buttonTextStyle),
),
BottomNavigationBarItem(
icon: Icon(GaeoIcons.location_on, color: Colors.white),
title: Text('Adresses', style: buttonTextStyle),
),
BottomNavigationBarItem(
icon: Icon(GaeoIcons.group, color: Colors.white),
title: Text('Responsables', style: buttonTextStyle),
),
BottomNavigationBarItem(
icon: Icon(GaeoIcons.truck, color: Colors.white),
title: Text('Distributions', style: buttonTextStyle),
),
BottomNavigationBarItem(
icon: Icon(GaeoIcons.group, color: Colors.white),
title: Text('Contacts', style: buttonTextStyle),
),
BottomNavigationBarItem(
icon: Icon(GaeoIcons.comment, color: Colors.white),
title: Text('Commentaires', style: buttonTextStyle),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
);
}
}`
您可以通过包含的图片了解我的意思
谢谢你的帮助
解决方案
我已尝试使用 Story App UI 模拟您的情况,
请尝试
1. 添加 BottomNavigationBar 的 backgroundColor
2. 使用 BottomNavigationBarType.fixed 和 fixedColor 进行测试
还参考Flutter BottomNavigationBar 颜色
代码片段
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Colors.brown,
type: BottomNavigationBarType.fixed,
fixedColor: Colors.white,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
backgroundColor: Colors.white,
icon: Icon(Icons.access_time, color: Colors.white),
title: Text('Edifice', ),
),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm, color: Colors.white),
title: Text('Adresses', ),
),
],
)
使用 BottomNavigationBar 的 Story App UI 测试结果
推荐阅读
- python - Python使用子类的类属性作为默认参数而不覆盖方法
- javascript - 使用导航栏动态显示/加载 React.js 组件?
- c++ - 使用 CMake 找不到 D3DX11.lib
- python - 直接导航到没有 URL 的页面 (BeautifulSoup)
- python - Urllib 从用户收集 url 时显示语法错误
- json - Typescript 抱怨导入的 json 模块缺少分号
- maven - 将具有不同 groupId 的工件组合起来进行 Maven 解析
- excel - 如何将一个数组中的值分配给另一个数组中的变量
- javascript - 在 Vue.js 中使用唯一值填充嵌套对象数组的下拉列表
- javascript - AWS Amplify GraphQL 查询返回 null 而不是 items 数组