Skip to content

Using bundled package assets

This feature is introduced in Spider v4.1.0

If the package you're using is bundling its package assets (You can read more about it on offical Flutter docs here.) and has exposed generated dart references for bundled package assets, then you can use them in your application too.

IMPORTANT:

It is a hard requirement from Flutter that you must specify each and every asset path individually in the assets section of your application's pubspec.yaml. Otherwise AssetBundle won't be able to find the package assets. So specifying packages/<package_name>/images/ doesn't work.

This is how you have to specify assets in your application's pubspec.yaml file.

flutter:
  assets:
    - packages/<package_name>/images/image1.png
    - packages/<package_name>/images/image2.png
    - packages/<package_name>/images/image3.png
    - packages/<package_name>/images/image4.png
    - packages/<package_name>/images/image5.png

Once you have this configuration in your application, You can use those package references just like how you use your own asset references.

for example,

Image.asset(PackageImages.image1);

Keep in mind that, for this to work, the package itself has to include dart references for the assets put inside lib of the package.