With Visual Studio Code, I can’t use relative path for all assets. I must use the full path to show any asset images. When I’m using a relative path, the image doesn’t appear.
Do you know how to use relative paths in Visual Studio?
pubspec.yaml
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- diolos/assets/images/
When I link an imagem I must add the full path.
Image.asset(
height: 50,
"/Users/ogosselin/Documents/Projets/AppMobile/diolos/assets/images/diolosLogoVioletEntete.png"),
Image doesn’t appear with a relative path, but it works with the full path.
Update : I have the preview but same behavior
The following assertion was thrown resolving an image codec:
Unable to load asset: "diolos/assets/images/diolosLogoBlancEntete.png".
Exception: Asset not found
3
Answers
It looks like diolos is your project name, so the path to the assets folder in the pubspec.yaml file should be:
open vs code right click on asset and click
copy relative path
and then paste this inpubspec.yaml
file.First of all your assets folder will look like this:
Then in your
pubspec.yaml
file add assets like this:And use it like this: