how to convert String value to Icons value in Flutter, i'm getting Icon value from json as a String.
I got following error when i'm tried to Use that value
error: The argument type 'String' can't be assigned to the parameter type 'IconData'. (argument_type_not_assignable at [hippo] lib\screens\dynamic_list.dart:71)
{
"page": 1,
"MenuItems": [
{
"id": 419701,
"icon": "MdiIcons.account",
"name": "account"
},
{
"id": 419702,
"icon": "MdiIcons.currencyUsd",
"name": "Funds"
},
{
"id": 419703,
"icon": "MdiIcons.home",
"name": "home"
}
]
}
You can do it by using Icon class constants according to official Flutter docs.
Icon(IconData(61668, fontFamily: 'MaterialIcons'));
Check more Icon class constants here: https://api.flutter.dev/flutter/material/Icons-class.html#constants
you can use Icon class constants according to official Flutter docs. (https://api.flutter.dev/flutter/material/Icons-class.html#constants)
example:IconData(0xf518, fontFamily: 'MaterialIcons')
also you can generate custom images to font icon (Generate to font). save ttf file in assets. pass unicode data (like "e90a").
example:
Icon(IconData(int.parse('0x${e90a}',
fontFamily: 'family name given in the link above'));
use flutter_remote_icon
var remoteIconData = new RemoteIconData("material://Icons.add"); // -> native material icons remotely (dynamically)
return RemoteIcon(icon: remoteIconData);
https://github.com/softmarshmallow/remote-ui/tree/master/flutter/packages/flutter_remote_icon
https://pub.dev/packages/flutter_remote_icon
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