19

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.

0

2 Answers 2

26

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),
),
Sign up to request clarification or add additional context in comments.

4 Comments

This requires "The image to display as the icon." So it's looking for an image, not a glyph
I'm trying to understand why you want an Icon. Do you already have your image converted to a glyph? If so, can you put a complete code sample up and show the full error message you're getting?
Over 100 icon images (x3 for different screen resolutions) becoming a footprint and maintenance nightmare. Yes, all image art has been converted to a custom icon font. Error is because the image expects a string for "imagename.png", but font glyph data can't be specified as a string.
Will put up a code sample later - at work now and can't pause
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.