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.


Solution 1: Günter Zöchbauer

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.


Solution 2: Bohdan Uhrynovskiy

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.


Solution 3: Smily

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.