[英]Custom Bottom Navigation Bar Item Decoration in Flutter
I am trying to build something like this UI我正在尝试构建类似这样的UI
In this the selected Bottom Navigation Bar Item should be highlighted with a background color.在此选定的底部导航栏项目应以背景颜色突出显示。
Currently, I've done this:目前,我已经这样做了:
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
fixedColor: Colors.black,
currentIndex: _selectedIndex,
showSelectedLabels: false,
showUnselectedLabels: false,
onTap: _onItemTapped,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home_outlined),
label: '',
),
BottomNavigationBarItem(
icon: Icon(Icons.checklist_outlined), label: ''),
BottomNavigationBarItem(
icon: Icon(Icons.file_copy_outlined), label: ''),
BottomNavigationBarItem(
icon: Icon(Icons.notifications_outlined), label: ''),
BottomNavigationBarItem(
icon: Icon(Icons.settings_outlined), label: ''),
],
),
If you want the selected tab to have yellow background color when selected, one way is to wrap the icon with a Container and set color based on _selectedIndex如果您希望选定的选项卡在选择时具有黄色背景色,一种方法是使用 Container 包装图标并根据 _selectedIndex 设置颜色
icon: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: _selectedIndex == 0 ? Colors.yellow : Colors.transparent,
borderRadius: BorderRadius.circular(200)
),
child: Icon(Icons.home_outlined)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.