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

后端 未结 11 1242
死守一世寂寞
死守一世寂寞 2020-12-24 11:22

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 f

相关标签:
11条回答
  • 2020-12-24 12:00

    Spaces are significant in YAML

    assets is indented too far

    flutter_test:
      sdk: flutter
    
    flutter:
      uses-material-design: true
      assets:
        - loadjson/person.json
    
    0 讨论(0)
  • 2020-12-24 12:02

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

    0 讨论(0)
  • 2020-12-24 12:04

    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.

    0 讨论(0)
  • 2020-12-24 12:06

    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

    0 讨论(0)
  • 2020-12-24 12:06

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

    0 讨论(0)
  • 2020-12-24 12:07

    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
    
    0 讨论(0)
提交回复
热议问题