fluttercommunity / font_awesome_flutter

The Font Awesome Icon pack available as Flutter Icons
Other
831 stars 233 forks source link

Dynamic icon retrieval required regular font to be available #244

Closed timkandel closed 1 year ago

timkandel commented 1 year ago

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 commented 1 year ago

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

michaelspiss commented 1 year ago

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.