I was developing a Flutter package and everything is ok, but I'm unable to find a way to properly load assets into the library. I've been looking for a solution and I found that one way to include the assets is creating an "assets" folder inside "lib" folder, then in pubspec.yaml specify the path, something like:
assets:
- packages/ecx_mail_module/assets/svg/
- packages/ecx_mail_module/assets/img/
- packages/ecx_mail_module/assets/img/imag_fondo_correo.png
Then I'm loading the asset as showed next:
Container(
height: size.height * 0.82,
width: size.width * 0.6,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'packages/ecx_mail_module/assets/img/imag_fondo_correo.png', // the asset
),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20),
),
),
child: ...,
),
The architecture of the is the next one:
|
|---lib
| |
| |---main.dart
| |---[other folders for the package]
| |---assets
| |
| |---img
| |---svg
|
|---pubspec.yaml
All those assets are used on a component inside the library, but when I try to use one of those components on my project (or even in the example folder of the library) the assets are still not loaded, giving me the next error:
Notice that for some reason the prefix "assets/" is added at some point, but I don't know where or if it's the source of the problem, but there are no option to remove that prefix on the component that I'm using to render the image:
I also tried to load the resources using the next structure but the exact same error occurs:
Removing the "assets" word from the path didn't work neither.
I have tried moving the "assets" folder at the same level as the lib folder but that didn't work, also I changed the way the assets are imported in "pubspec.yaml" to only specify the path without the package name (assets/img/imag_fondo_correo.png
) but it does not work. So, am I missing something? I tought the problem was the AssetImage
component but some libraries such as the flutter_svg
one are giving me the same error (also adding the "assets/" prefix on the path idk if that's the problem) when using SVGs.