In a Flutter app, initially many icons were implemented as png images in their 3 sizes like so:
child: new Image(
image: new AssetImage(widget.featureNavMenu.image),
),
which expects a string
image: "assets/images/superCheckMark.png",
Now, I want to convert the children to a custom icon font (font glyphs).
However, changing to this...
child: new Icon((icon), size: 25.0,),
and trying to get it to accept this...
new Icon(MyIcons.superCheckMark, size: 30.0, color: Colors.white,),
breaks the app.
What is the correct way to get the app to accept an icon instead of image? I've actually tried many different things according to Flutter's somewhat general documentation and am stumped.
IconData class Null safety A description of an icon fulfilled by a font glyph. See Icons for a number of predefined icons available for material design applications. @immutable.
Instead of Image
, you can use the ImageIcon
class. This will give you a widget that behaves like an Icon
.
ImageIcon(
AssetImage("images/icon_more.png"),
color: Color(0xFF3A5A98),
),
I was looking for this because I thought the leading
element of a ListTile
needed to be an Icon
. So when I encountered issues creating an Icon from an Image, I got led here.
finally I found out ListTile will take an Image just fine
ListTile(
leading: Image.network(friend_map['picture_url']),
title: Text(full_name),
subtitle: Text(uuid_shorten),
),
I recommend you look at the parent object that required an Icon, see if it does not support Image object instead. or has a sibling widget that does..
hope this helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With