flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.17k stars 26.65k forks source link

Icons: add method fromName(iconName) #145302

Open javaone199 opened 1 month ago

javaone199 commented 1 month ago

Use case

Icon names are retrieved from server. So a method for getting IconData from icon name is needed.

Icons.fromName(iconName)

iconName is the same as the constant name in Icons class.

pub.dev package material_icon_design_flutter does not contain many of the IconData constants defined in Icons, so it is not designed to provide name mappings for the Icons class.

Proposal

Add a new method for mapping names to IconData constants:

IconData Icons.fromName(iconName)

maurovanetti commented 1 month ago

What about tree shaking though?

goderbauer commented 1 month ago

Can you elaborate how the icon would be identified by name? Currently, icons work with a custom font and you can use IconData to specify an Icon by code point and font family.

flutter-triage-bot[bot] commented 1 month ago

The triaged-design label is irrelevant if there is no team-design label or fyi-design label.

github-actions[bot] commented 1 month ago

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.

github-actions[bot] commented 2 weeks ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

darshankawar commented 2 weeks ago

Reopening this as OP filed duplicate issue, as this issue was locked for conversation.

@javaone199 Please share your findings or reply on above question asked.

javaone199 commented 2 weeks ago

Add the following method to Icons class.

static IconData fromName(String iconName) { return iconMap[iconName]; }

iconName is a pre-defined constant name in Icons class.

From the IconData doc, instantiating IconData instead of using the predefined IconData constants will cause tree-shaking issue.