78

I'm using JSON file and register in Pubspec.ymal but showing error and also when I use an image and register it, the same error also occurs. Maybe there is a formatting mistake in it, but don't know what the problem is.this is the doc I followed.

Error on line 29, column 5 of pubspec.yaml: Expected a key while parsing a block mapping. assets: ^

This is my pubspec.yaml file

name: jsondata description: A new Flutter application.

  dependencies:  

  flutter:

  sdk: flutter

  cupertino_icons: ^0.1.0

  dev_dependencies:   

 flutter_test:

      sdk: flutter

    flutter:

    uses-material-design: true

      assets:

       - loadjson/person.json

enter image description here

Farhana Naaz Ansari
  • 8,382
  • 15
  • 63
  • 97

12 Answers12

213

Spaces are significant in YAML

assets is indented too far

flutter_test:
  sdk: flutter

flutter:
  uses-material-design: true
  assets:
    - loadjson/person.json
Günter Zöchbauer
  • 490,478
  • 163
  • 1,733
  • 1,404
18

It is because of the indentation of your code.The uses-material-design should be on the same line vertically as the assets:.

 uses-material-design: true

 assets:
   - images/picture.png
EngineerDanny
  • 512
  • 6
  • 9
15

Error on line 29, column 4: Expected a key while parsing a block mapping. assets:

flutter: uses-material-design: true assets: - assets/images/image.jpg

In my case i just added # in front of uses-material-design: true

Try below code

flutter:   

  # uses-material-design: true 

   assets: 
    - assets/images/image.jpg

its working fine.

Alien
  • 11,017
  • 3
  • 29
  • 45
  • 4
    That's probably because the indentation of `uses-material-design: true` was wrong. Commenting it out is not really an option if you want to use material. – Günter Zöchbauer Jul 19 '18 at 06:15
  • I commented the `uses-material-design` and then did `Packages get` and then uncommented the same to re run on the simulator. Worked fine – Abhishek Bedi Jan 05 '19 at 19:29
6

In my case, uses-material-design indentation was broken. I put 1 (one) more space before it, and it worked fine.

Bartek Pacia
  • 533
  • 1
  • 10
  • 22
4

With removed comments, original, generated by default pubspec.yaml looks like this

flutter:
  uses-material-design: true
   assets:
    - images/abc.jpg

But it isn't vaild. It doesn't works. It should be:

flutter:
  uses-material-design: true
  assets:
    - images/abc.jpg

Important: Spaces are significant in YAML

2

Spaces are very important in .yaml file.

Just make sure your code is on the same line (vertically) according to key and value.

Or

If you are still confused please watch this simple video. It'll help you to solve the issue easily.

https://imgur.com/gallery/ngoXwUe

Haseeb Nazir
  • 186
  • 1
  • 10
1

**Error on line 46, column 4: Expected a key while parsing a block mapping. assets:

flutter: uses-material-design: true assets: - assets/dhaka.jpg**

Make sure when you uncomment the line please check indentation. if indentation is wrong it's going error. flowing this image. Happy coding !!!

enter image description here

amirul
  • 112
  • 2
  • 10
1

You have to be careful with space in yml file

Achraf Farouky
  • 199
  • 1
  • 8
0

In My Case, the image was too large to load, decreasing dimension of image worked.

DCS
  • 159
  • 2
  • 2
  • 13
0

Please make sure that we don't have unwanted whitespace since yaml structure is sensitively considering the white spaces. Please refer the documentation for more info as below link,
https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html

Deva
  • 1,576
  • 13
  • 15
0

As @Baftek mentioned , just indent before uses-material-design:true and press Ctrl+Alt+l (Intellij or Android Studio) to reformat file.

Sumit Shukla
  • 2,722
  • 3
  • 21
  • 30
0

Issue is related with indent spacing, check your spacing, it should work fine
fonts: - family: CM Sans Serif fonts: - asset: assets/fonts/cm_sans_serif_2012.ttf

msk_sureshkumar
  • 283
  • 4
  • 10