I want to create my own icons. For this, I created CustomIcon with the extension.
extension CustomIcons on Icon {
Icon get panelIcon =>Icon(
icon: SvgPicture.asset("asset/svg/one.svg", semanticsLabel: 'One') ,
color: Colors.red,
);
}
}
I want to use my CustomIcon in the form of Icon(Icons.panelIcon). I am getting the error in the photo. How can I do this?
2
Answers
I’m not exactly sure how to extend
Icon
widget with custom icons, but this is how I suggest doing it:Then you can simply use it by calling:
Few things to know :
icon
ofIcon
class is of typeIconData?
.IconData
is font character and not an image. It is part of "MaterialIcons" font.Here are the steps to achieve it :
Make an extension on
Icons
class and notIcon
.Create a custom font with your svg pictures using this website : https://icomoon.io/app
Import the font in your flutter project assets
Write your code like so
NB: You will easily get CHARACTER_CODE on iconmoon.io. Check this as example. 👇🏽