Search code examples
flutterdart

How can I get Flutter material icon dynamically


I have the name for the icon returned from the api, for example like this:

{
  "iconName": "home"
}

So i want to display it in my application:

 icon: Icon(Icons.home)

But this icon can be any from the Icons class, so I don't want to make a helper class or HashMap to handle this.

Is there anyway to do this with reflection like in Java, or some better way?

Thanks.


Solution

  • Ok for now I implemented a Map for this. If anyone need it, it can be find here.

    UPDATE:

    If you reference all icons, all of them will be in your bundle. So pick only the icons you need to keep them in the Map.

    Thanks to @RedAu for his comment, to explain this.