Flutter: Use Icon Font From Another Package

1.2k views Asked by At

I developed separated UI package for my project.

Here is it's simplified structure:

project:
│
...
│
├── lib:
│   │
│   └── classes using AppIcons.ttf:
│
└── packages:
    │
    └── ui-kit:
        │
        ├── lib:
        │   │
        │   └── classes using AppIcons.ttf:
        │
        └── assets:
            │
            └── icons:
                │
                └── AppIcons.ttf:

packages/ui-kit/pubspec.yaml:

flutter:
  fonts:
    - family: AppIcons.ttf
      fonts:
        - asset: assets/icons/AppIcons.ttf

packages/ui-kit/app_icons.dart:

abstract class AppIcons {
  
  static const _kFontFam = 'AppIcons';

  static const IconData ic_add = IconData(0xe800, fontFamily: _kFontFam);
  
   ...

}

The question is - How can I use AppIcons.ic_add inside lib/

So when I tried to place icon (Icon(AppIcons.ic_add)) I always get placeholder instead of my icon

Please tell me if it possible to use icons placed outside root package

and how can I implement it

1

There are 1 answers

0
Sergey Lobanov On BEST ANSWER

Finally I solved this question.

For those who faced the same problem here is my solution:

packages/ui-kit/app_icons.dart:

...

flutter:
  fonts:
    - family: AppIcons.ttf
      fonts:
        - asset: packages/ui-kit/assets/icons/AppIcons.ttf

...

This solution applies to all types to assets outside root app package.