问题
I searched it on Stackoverflow but regarding flutter, I do not find any relevant solution, here and here may be the same question but they are not for flutter.
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
回答1:
Spaces are significant in YAML
assets
is indented too far
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- loadjson/person.json
回答2:
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.
回答3:
In my case, uses-material-design
intendation was broke. I put 1 (one) more space before it, and it worked fine.
回答4:
In My Case, the image was too large to load, decreasing dimension of image worked.
回答5:
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
回答6:
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
来源:https://stackoverflow.com/questions/50171766/flutter-pub-expected-a-key-while-parsing-a-block-mapping-path