How to use custom icon fonts in flutter
To use your Flutter Icon font from a custom package, you can follow these steps:
create a flutter icon font
You can use flutter icon for that https://www.fluttericon.com
Put the file into your package
Make sure to copy the `.ttf` file **into of the `/lib` folder**.
NOT just assets, as you would do in your root project.
Example path:
/packages/my_awesome_fontpackage/lib/assets/MyIconFont.ttf
(see https://zubairehman.medium.com/how-to-use-custom-fonts-images-in-flutter-package-c2d9d4bfd47a )
Add the font to your project
Now open your package’s `pubspec.yaml` file and add the font as an asset with package path:
flutter:
fonts:
— family: MyIconFont
fonts:
— asset: packages/my_awesome_fontpackage/assets/MyIconFont.ttf
(you might have to restart your app and bundling completely for the font to be loaded correctly and maybe run `flutter clean` just to be sure)
Now add package declaration to font dart file
Go into the `my_icon_font.dart` file and change the constant `_kFontPkg` there to your package name.
class MyIconFont {
MyIconFont._(); static const _kFontFam = ‘MyIconFont’;
static const String? _kFontPkg = ‘my_awesome_fontpackage’; static const IconData bell = …
….
}
Let me know if that helped or if you have any questions. :)