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'
Author by
Alb
Updated on January 02, 2023Comments
-
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 about 2 yearsI'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 about 2 yearsyeah. this is exactly what you should be doing as assets are placed inside that pacakge.
-
mirkancal almost 2 yearsthanks for the input but how this is different than my answer? any benefits of using lib/assets folder instead of the assets folder?
-
Alb almost 2 yearsI will test this today. I still have some trouble with having duplicate assets folders though :/
-
mirkancal almost 2 yearsWhy 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 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