Search code examples
flutterdartflutter-layoutflutter-assetimage

Flutter image not showing


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


Solution

  • 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/