[英]How to display an image in the BottomNavigationBar in Flutter?
ImageIcon(
AssetImage("images/icon_more.png"),
color: Color(0xFF3A5A98),
),
代替
new BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
改成这个
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage("images/icon_more.png"),
color: Color(0xFF3A5A98),
),
title: Text('Home'),
),
所以显然解决方案是使用 Image.asset('image_path') for icon/activeIcon in BottomNavigationBarItem 如果您想将图像显示为具有原始颜色的底栏导航图标。
但是,如果您的items: const <BottomNavigationBarItem>[]
中包含关键字const
,它确实会出错。 如果你删除它,你应该能够使用Image.asset
而不是ImageIcon
(着色着色)
正如@asbah-riyas 提到的,可以通过将ImageIcon
小部件提供给BottomNavigationBarItem
的icon
参数来完成。 虽然您不需要在其中指定color
NavigationBarItem 的图像属性需要一个小部件,而不是一个图标,所以我可以使用它。 BottomNavigationBarItem(icon: Image.asset('images/symbol.png')),
正确答案是 BottomNavigationBarItem(icon: Image.asset('images/symbol.png')),
如果您将您的 png 图像放置在 images 文件夹中,并且在您的资产下的 pubspeq.yaml 中提及的 images/image.png 相同
您可以改用它:
BottomNavigationBarItem(
icon: Image.asset(" your image here "),
),
label: 'home',
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.