flutter icon indicating copy to clipboard operation
flutter copied to clipboard

Proposal to add an IconImage widget

Open animator opened this issue 2 years ago • 2 comments
trafficstars

Is there an existing issue for this?

Use case

Just like one can create ImageProviders from assets, network, and memory. There should be a way to create an image from IconData. It will save a lot of time and will be very convenient as the builtin icons can be directly used instead of downloading it as a png/jpg and adding it to the assets.

We already have a ImageIcon widget. Why not have something the other way around?

Example Use Case:

SwitchListTile requires activeThumbImage and inactiveThumbImage which need to be ImageProviders. I want to use pre-built icons that are already shipped with flutter, but unable to do so directly as there is no way to convert an icon into an image.

Proposal

An IconImage widget that provides Icons.heart (example) as an Image.

animator avatar May 04 '23 02:05 animator

We already have a ImageIcon widget. Why not have something the other way around?

i don't think its trivial to do so, as Icon is actually text + fontFamily. it'll be simpler to have 2 APIs, one for each. although i'll let others with more experience o weigh in on this.

SwitchListTile requires activeThumbImage and inactiveThumbImage which need to be ImageProviders. I want to use pre-built icons that are already shipped with flutter, but unable to do so directly as there is no way to convert an icon into an image.

for this particular usecase, SwitchListTile.thumbIcon was recently added (PR), which enables using an icon for a thumb. (Switch has had this since a long time). but, looks like its not in stable yet, so it'll be released soon.

werainkhatri avatar May 06 '23 09:05 werainkhatri

Thanks for looking into it @werainkhatri and also for letting me know about SwitchListTile.thumbIcon which is my current use case. Will definitely wait for a reply on ImageIcon from others.

animator avatar May 06 '23 13:05 animator