0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes sir it worked when i care about gaps. Thanks for it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.