Reputation: 41
The image is not showing. While running, it shows this error but it is running without image. I have used tab between the '-' and the image path. I have also created a folder called assets and a subfolder slider_icons and included my images in it.
This is exactly how my pubspec.yaml looks like,
flutter:
uses-material-design: true
assets:
- assets/slider_icons/burger.png
- assets/slider_icons/pizza.png
- assets/slider_icons/biryani.png
- assets/slider_icons/parotta.jpeg
- assets/slider_icons/cup.png
- assets/slider_icons/drink.png
- assets/slider_icons/chicken-fries.png
Error:-
[foodie] flutter pub get
Error detected in pubspec.yaml: Error on line 48, column 7: Expected a key while parsing a block mapping. ╷ 48 │ assets: │ ^ ╵ Please correct the pubspec.yaml file at F:\Learn flutter\foodie\pubspec.yaml exit code 1
This is the screen shot of my screen
Upvotes: 0
Views: 307
Reputation: 566
The word assets:
has to go exactly under the #
and the -
needs two spaces. Additionally, when you use images from the same folder you can add all the images with one line as written below.
How it should be written:
# To add assets to your application, add an assets section, like this:
assets:
- assets/slider_icons/
Upvotes: 1
Reputation: 1
The way to include an image inside Flutter is:
flutter:
assets:
- assets/my_icon.png
- assets/background.png
You also have to create a directory where you can put the resource inside it.
Upvotes: 0