Flutter makes use of the Dart packaging system, pub. Via your applications pubspec.yaml file (or simple pubspec), you can pull down packages from the flutter ecosystem, or the broader dart community.
Anyway, i need to add some images to my flutter application, and so had to add an assets section to the pubspec.the default Android Studio generated apps pubspec has a lot of commented out code with explainations about what is going on, e.g
Anyway, i need to add some images to my flutter application, and so had to add an assets section to the pubspec.the default Android Studio generated apps pubspec has a lot of commented out code with explainations about what is going on, e.g
# To add assets to your application, add an assets section, like this:# assets: # - images/a_dot_burr.jpeg # - images/a_dot_ham.jpeg# An image asset can refer to one or more resolution-specific "variants", see # https://flutter.io/assets-and-images/#resolution-aware.
So I uncommented these lines
# assest :
-
-
-
# - images/a_dot_ham.jpeg
with the idea from these comment. that i would just edit it to suit my particular needs. Once you have edited your pubspec, you need to click on the "Get dependencies" option near the toolbar at the top of the IDE.
# To add assets to your application, add an assets section, like this:assets: - images/diamond.png - images/circle.png #- images/a_dot_ham.jpeg
when I run my application. I got an error
Performing hot reload...
Error on line 44, column 4: Expected a key while parsing a block mapping.
╷
44 │ assets:
│ ^
╵
Error detected in pubspec.yaml:
Fortunately, because I understand YAML some, the solution was simple - just fix the formatting of the file. YAML has rules about indentation when creating 'sections' in your configuration. You will notice in the above screenshot that the alignment betwen "uses-material-design" and "assets" is out of whack.
The simple fix was to make sure my assets section was aligned to my user-material-design section:
uses-material-design: true # To add assets to your application, add an assets section, like this:assets: - images/diamond.png #- images/a_dot_ham.jpeg
Now when I click on "Get dependencies" all is well. simple issue to fix, but hopefully reading this article will save you some time !
Feel free to contact me . Let me know if you still have an issue .
Nice content. It helps to solve my problem and provide me more knowledge about YAML file which the configration file of flutter application(how it actually works ). Thanks you so much
ReplyDeleteIt indicates a missing or incorrect syntax element, like a missing brace or quotation mark. How Win Game Double-check the code for proper formatting and ensure that all opening and closing elements are balanced to avoid this error during parsing.
ReplyDelete