Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assets does not see subfolders

Tags:

flutter

assets does not see subfolders. If folder /image.png - then all the rules. If folder /subfolder/image.png - writes: Unable to load asset

Is there a solution or is it supported?

Required for offline maps in flutter_map.

like image 510
KnightsForce Avatar asked Feb 20 '19 10:02

KnightsForce


3 Answers

All you need is to provide all folders and subfolders.

Check official doc:

Note that only files located directly in the directory will be included; to add files located in subdirectories, create an entry per directory.

But if you need to provide different scales (like 1.5x, 2.0x, 3.0x) you don't need to mention these subfolders in pubspec.yaml.

like image 109
Bohdan Uhrynovskiy Avatar answered Oct 27 '22 15:10

Bohdan Uhrynovskiy


I had similar problem when started, and my problem was:

Add asset file to pubspec, like

flutter:
  assets:
    - subfolder/image.png

Then using it like AssetImage('mage.png')

The problem here was that you should still provide the full path, as in: AssetImage(subfolder/image.png)

Please check AssetImage class for more examples.

like image 38
Smily Avatar answered Oct 27 '22 15:10

Smily


Not sure what the problem is exactly, but you need to list every folder that contains assets. The files in the listed folder and in resolution sub-folders (like 1.5x/, 2.0x, 3.0x, ...) are then found automatically,
but other sub-folders are ignored.

like image 22
Günter Zöchbauer Avatar answered Oct 27 '22 16:10

Günter Zöchbauer