[英]I can't add the image from assets file in Flutter
I'm new at flutter and I want to add a picture to my app.我是 flutter 的新手,我想在我的应用程序中添加一张图片。 I coded something like this;
我编写了这样的代码;
body: Center(
child: Image(
image: AssetImage('assets/cartman.png'),
)),
And my.yaml file is;而my.yaml文件是;
# To add assets to your application, add an assets section, like this:
assets:
-assets/cartman.png
And my error output is;我的错误 output 是;
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.
提前致谢。
Spacing matters, make sure it is 2 spacebar away from the start, and the dash can start from the same line as assets.间距很重要,确保它距离起点 2 个空格键,并且破折号可以从与资产相同的行开始。 Also, if your assets folder is in lib, you need to add the lib directory.
此外,如果您的资产文件夹在 lib 中,则需要添加 lib 目录。
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.
您可以在资产内的文件夹中放置任意数量的图像,并使用 1 行代码访问它们,就像我上面的代码一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.