Gjoko Bozhinov
Gjoko Bozhinov

Reputation: 1177

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.

Upvotes: 2

Views: 966

Answers (1)

Gjoko Bozhinov
Gjoko Bozhinov

Reputation: 1177

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.

Upvotes: 5

Related Questions