0

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

6
  • 1
    add code please Commented Nov 8, 2020 at 12:44
  • I added the coding now Commented Nov 9, 2020 at 7:19
  • Can you provide the error code as well? Commented Nov 9, 2020 at 7:28
  • check log,did it display any errors? Commented Nov 9, 2020 at 7:50
  • Yes it displays error...I will post the error too Commented Nov 9, 2020 at 8:43

2 Answers 2

1

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/
Sign up to request clarification or add additional context in comments.

1 Comment

if you have deleted the default comment you should just add 2 spaces from the beginning of the word, assets:
0

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.

1 Comment

I did this exact way...But still the image isn't showing. I have also created the folders and brought all the images into the folder

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.