Flutter Pub: Expected a key while parsing a block mapping. path:

Hello Guys. Many times we Face Flutter Pub: Expected a key while parsing a block mapping. path:. So in this tutorial, we are going to Solve this error.

So Error That I have faced is as below.

Error on line 30, column 6 of pubspec.yaml: Expected a key while parsing a block mappingassets: ^

Here is my pubspec.yaml File:

  dependencies:  

  flutter:

  sdk: flutter

  cupertino_icons: ^0.1.0

  dev_dependencies:   

 flutter_test:

      sdk: flutter

    flutter:

    uses-material-design: true

      assets:

       - loadjson/person.json

Solution:

Question: How to Solve Flutter Pub: Expected a key while parsing a block mapping. path ?
Answer: It is because of the indentation of your code. Spaces are significant in YAML. so you have to manage all lines in indentation. in my case assets is indented too far. that’s why I am facing that error.

It is because of the indentation of your code.

Spaces are significant in YAML. so you have to manage all lines in indentation.

in my case assets is indented too far. that’s why I am facing that error.

flutter_test:
  sdk: flutter

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

So its all About Spaces are significant in YAML so you cant add extra space in yaml file else it will cause error Flutter Pub: Expected a key while parsing a block mapping. path:

Here is Git issue #1347

Now, Error is solved. If you still facing this error so Comment below your error with code. I Will help You. Comment below Your thoughts and your queries. And Also Comment on your suggestion here.

Also Read

Milan Dhameliya is an Information Technology Engineer. By profession, he is a Full Stack developer with knowledge of multiple back-end platforms (e.g., PHP, Node.js, Python) and frontend Flutter frameworks.

Leave a Comment