-1

When creating a custom package that contains font as a .ttf file. I try to download the font file also in the example app that is contained in the package.

The font is downloaded successfully on iOS and macOS apps but not on Linux or Web.

The web console is giving me an error Failed to load font My-Custom-Icons at assets/../lib/assets/fonts/My-Custom-Icons.ttf

...

my_package:
  

    # When depending on this package from a real application you should use:
    #   custom_package: ^x.y.z
    # See https://dart.dev/tools/pub/dependencies#version-constraints
    # The example app is bundled with the plugin so we use a path dependency on
    # the parent directory to use the current plugin's version.
    path: ../

...


flutter:
  uses-material-design: true
  
  fonts:
    - family: My-Custom-Icons
      fonts:
        - asset: ../lib/assets/fonts/My-Custom-Icons.ttf


I would expect that font would be downloaded the same way on all different platforms. What I'm missing here?

Niko Lipponen
  • 31
  • 1
  • 3

2 Answers2

0

Hi just replace this and try.

- asset: assets/fonts/My-Custom-Icons.ttf
  • Hi, thanks for your reply! I did try this but didn't work. The problem is that the example project doesn't contain the fonts. The package does which is the parent of the example app. I can import the font from a project that uses the package just like instructed in "https://docs.flutter.dev/cookbook/design/package-fonts" But I can't use that syntax in the example project inside the package itself. What is now giving me a headache is that the "../" path is working correctly in iOS and macOS but not in web and linux. – Niko Lipponen Nov 24 '22 at 08:41
0

Ah, it seems that you can use the packages path when importing the font even inside the example. So the following did the work.

...

my_package:
  

    # When depending on this package from a real application you should use:
    #   custom_package: ^x.y.z
    # See https://dart.dev/tools/pub/dependencies#version-constraints
    # The example app is bundled with the plugin so we use a path dependency on
    # the parent directory to use the current plugin's version.
    path: ../

...


flutter:
  uses-material-design: true
  
  fonts:
    - family: My-Custom-Icons
      fonts:
        - asset: packages/my_package/assets/fonts/My-Custom-Icons.ttf

Niko Lipponen
  • 31
  • 1
  • 3