Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - how to convert an image definition into an icon definition?

Tags:

flutter

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.

like image 306
Deborah Avatar asked Sep 07 '17 17:09

Deborah


People also ask

What is icon data in Flutter?

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.


2 Answers

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),
),
like image 182
Collin Jackson Avatar answered Sep 18 '22 18:09

Collin Jackson


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.

like image 23
Mathieu J. Avatar answered Sep 21 '22 18:09

Mathieu J.