Reputation: 551
I need a library to load an SVG (using the flutter_svg package) located in the main app's assets directory. Right now I have the following code in the library function:
SvgPicture.asset(svgSrc, package: 'example_app')
Where svgSrc will be 'assets/images/logo.svg'.
However on flutter run I get the following exception:
Error while trying to load an asset: Failed to load asset at "assets/packages/example_app/assets/images/logo.svg" (404)
══╡ EXCEPTION CAUGHT BY SVG ╞═══════════════════════════════════════════════════════════════════════
The following assertion was thrown resolving a single-frame picture stream:
Unable to load asset: packages/example_app/assets/images/logo.svg
I have added the main app's pubspec.yaml I have:
assets:
- assets/images/
Where am I going wrong here?
Upvotes: 0
Views: 907
Reputation: 680
Here is an example showing how to share images via a custom package.
in answer to Jason's comment: it's just a question of paths. You can easily move packages
to any location until you can locate them in your pubspec.yaml
f.e. move it to one directory up and change pubspec.yaml
accordingly:
dependencies:
flutter:
sdk: flutter
flutter_svg: ^0.22.0
images:
path: ../packages/images/
another_package:
path: ../packages/another_package/
Upvotes: 2