【发布时间】:2020-11-24 11:07:02
【问题描述】:
我需要在底部导航栏上将自定义图像显示为图标。所以我创建了一个这样的类
class BottomBar extends StatefulWidget {
Function onPressed;
bool bottomIcons;
String text;
ImageIcon icons;
ImageIcon icons2;
BottomBar(
{@required this.onPressed,
@required this.bottomIcons,
@required this.icons,
@required this.icons2,
@required this.text});
@override
_BottomBarState createState() => _BottomBarState();
}
class _BottomBarState extends State<BottomBar> {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onPressed,
child: widget.bottomIcons == true
? Container(
decoration: BoxDecoration(
color: Color.fromRGBO(249, 68, 75, 0.08),
borderRadius: BorderRadius.circular(30),
),
padding:
EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 8),
child: Row(
children: <Widget>[
widget.icons2,
SizedBox(
width: 8,
),
Text(
widget.text,
style: TextStyle(
color: Color(0xfff9444b),
fontWeight: FontWeight.bold,
fontSize: 15),
),
],
),
)
: widget.icons);
}
}
然后像这样打电话
BottomBar(
onPressed: () {
setState(() {
bottomIcons = BottomIcons.Home;
home = true;
service = false;
shop = false;
});
},
bottomIcons:
bottomIcons == BottomIcons.Home ? true : false,
icons: ImageIcon(AssetImage('images/ichomeactive.png')),
icons2: ImageIcon(AssetImage('images/ichome.png')),
text: "Home"),
它工作正常,但它没有像我显示的那样显示正确的图标。
它是这样显示的
你可以看到它显示的主页图标和它在活动时显示的黑色主页图标。但问题是我没有这个黑色主页图标我有这个图标
但是当我在底部栏中调用这个粉红色图标但它显示为黑色时,我不知道它是怎么可能的。
【问题讨论】:
标签: flutter