Home > Blockchain >  Flutter - different asset path in package's example when building
Flutter - different asset path in package's example when building

Time:11-24

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?

CodePudding user response:

Hi just replace this and try.

- asset: assets/fonts/My-Custom-Icons.ttf

CodePudding user response:

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

  • Related