89
votes

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

14
have a look hereuser8667898
Which line is line 29?Günter Zöchbauer
The uses-material-design should be on the same alignment vertically as the assetsAnurag Sharma

14 Answers

261
votes

Spaces are significant in YAML

assets is indented too far

flutter_test:
  sdk: flutter

flutter:
  uses-material-design: true
  assets:
    - loadjson/person.json
22
votes

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
17
votes

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.

9
votes

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

7
votes

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

3
votes

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

1
votes

**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

1
votes

You have to be careful with space in yml file

1
votes

If images folder is next to lib folder, you need a ./, because it is not on the same level as the pubspec.yaml, then, in pubspec.yaml uncomment:

assets:
- ./images/   //Watch for spaces and indentation!!

Now you can use them:

Image.asset(
          '../images/nature.png',
          width: 600,
          height: 240,
          fit: BoxFit.cover,
        ),
1
votes

Get same problem after uncommenting assets and image link sample in pubspec.yaml.

If you faced problem with assets, like I was. Make sure that it starts with same column(starts with same indent as pre-defined property like uses-material-design). After uncommenting in my case, their location was different.

After that, the problem was solved.

0
votes

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

0
votes

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

0
votes

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

0
votes

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