I have a client config that is on a server in JSON format.
example JSON would be like { "icon" : "facebook" }
I have the widget below.
class MySocialIcons extends StatelessWidget {
MySocialIcons({this.icon, this.color});
final String icon;
final String color;
@override
Widget build(BuildContext context) {
switch(icon) {
case 'facebook': {
return Icon(FontAwesomeIcons.facebook, color: HexColor(color));
}
break;
case 'twitter': {
return Icon(FontAwesomeIcons.twitter, color: HexColor(color));
}
break;
default: {
return Icon(FontAwesomeIcons.home, color: HexColor(color));
}
break;
}
}
}
Is there a way to not have to write 500 switch statements for 500 font awesome icons? the format is
FontAwesomeIcons.facebook
where my string value "facebook" would append on the end of FontAwesomeIcons. I am looking for a way to just write whatever I want in the string and it return the correct icon widget.