Reputation: 5
I'm new at flutter and I want to add a picture to my app. I coded something like this;
body: Center(
child: Image(
image: AssetImage('assets/cartman.png'),
)),
And my .yaml file is;
# To add assets to your application, add an assets section, like this:
assets:
-assets/cartman.png
And my error output is;
Error detected in pubspec.yaml:
Error on line 48, column 4: Expected a key while parsing a block mapping.
╷
48 │ assets:
│ ^
╵
Please correct the pubspec.yaml file at
C:\Users\camur\AndroidStudioProjects\flutter_kurulum\pubspec.yaml
exit code 1
Can you help me about this? Thanks in advance.
Upvotes: 0
Views: 392
Reputation: 1904
Spacing matters, make sure it is 2 spacebar away from the start, and the dash can start from the same line as assets. Also, if your assets folder is in lib, you need to add the lib directory.
assets:
- lib/assets/imgs/
Also note that you do not have to add the names of each image. You can place as many images as you want in a folder inside assets, and access them all with 1 code line like my code above.
Upvotes: 1