'Assets in Flutter package are not visible in the app
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?
Solution 1:[1]
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'
Solution 2:[2]
Include the assets in your lib folder, and import it from local project only.
Assuming the project name ABC
:
Steps
- Create assets folder in lib, example:
lib/assets
. Full assets example url:ABC/lib/assets/some_asset.png
- Copy the assets in this folder.
- Import the assets in your pubspec.yaml like this:
assets:
- packages/ABC/assets/some_asset.png
Hope this help someone. :smiley:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mirkancal |
Solution 2 | Jesus Hernandez Barrios |