Assets in Flutter package are not visible in the app

118

After some digging, I've found a way to include it.

'packages/livescore_sdk/assets/default_team_logo.png' works instead of 'assets/default_team_logo.png'

Share:
118
Alb
Author by

Alb

Updated on January 02, 2023

Comments

  • Alb
    Alb over 1 year

    I've created a package, which uses some assets (sf2 file, ttf files, etc). Assets don't seem to load. I can fix this by including these files in the assets folder of my main project (so now, every asset in the package is also in my main project). However, when I build a web app, it still creates an extra folder for my package with the files that it needs.

    Is there a way around this? How do I enforce the package to use the assets from itself?

    • mirkancal
      mirkancal about 2 years
      I'm also building a flutter package with an example app in it. This package also has some widgets that I'm using in the example app. This widgets can't see the assets.
  • Ahmad Khan
    Ahmad Khan about 2 years
    yeah. this is exactly what you should be doing as assets are placed inside that pacakge.
  • mirkancal
    mirkancal almost 2 years
    thanks for the input but how this is different than my answer? any benefits of using lib/assets folder instead of the assets folder?
  • Alb
    Alb almost 2 years
    I will test this today. I still have some trouble with having duplicate assets folders though :/
  • mirkancal
    mirkancal almost 2 years
    Why do you have that issue? I'm keeping my assets in the package, reaching them the way I described above. I'm not duplicating any folders for that setup
  • Jesus Hernandez Barrios
    Jesus Hernandez Barrios almost 2 years
    "Anything in the lib/ folder will get automatically bundled with the app. Those assets will be available to anyone who uses your package. As the package developer, you don’t even need to declare those assets in pubspec.yaml if you are not using them yourself. They’ll still be bundled with the package".reference. If you are creating a package for the use of others,in lib/assets will be accessible, in external assets don't