Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic icon retrieval required regular font to be available #244

Closed
timkandel opened this issue Jun 9, 2023 · 2 comments
Closed

Dynamic icon retrieval required regular font to be available #244

timkandel opened this issue Jun 9, 2023 · 2 comments

Comments

@timkandel
Copy link

Describe the bug
If I generate my dynamic icon mapping file name_icon_mapping.dart while excluding the regular font it will lead into an error during build time.
If no icon with the corresponding css class is found, the method getIconFromCss will return FontAwesomeIcons.circleQuestion as a default.

To Reproduce
Steps to reproduce the behavior:

  1. Generate dynamic icon mapping without the the regular font $ configurator.sh --dynamic --exclude regular
  2. Import mapping file in your widgets import 'package:font_awesome_flutter/name_icon_mapping.dart';
  3. Build your app
  4. See error font_awesome_flutter/lib/name_icon_mapping.dart:36:26: Error: Member not found: 'circleQuestion'.

Expected behavior
The method generating the code for getIconFromCss should have some kind of fallback behavior to use an icon from an available font. Maybe regular -> solid -> light -> thin?
Even better would be to include a custom icon that's obviously broken / not from font awesome to avoid the very small problem if I want to include circle-question and something is wrong.

@timkandel
Copy link
Author

I'll try to add a pull request for the fallback method. Hope to find some time soonish :-)

michaelspiss added a commit that referenced this issue Jun 28, 2023
@michaelspiss
Copy link
Collaborator

michaelspiss commented Jun 28, 2023

Hi @timkandel and thanks for the feedback! I changed the function so it returns null if no icon is found. This way everyone can decide themselves how to treat missing icons by simply wrapping the function like

IconData customGetIconFromCss(String cssClasses) {
  return getIconFromCss(cssClasses) ?? FontAwesomeIcons.circleQuestion; // FontAwesomeIcons.circleQuestion being the placeholder icon here
}

This is definitely a much better solution that also eliminates the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants