我已经修改了我的pubspec.yaml
文件,通过添加我要添加的图片的文件夹路径,但我一个错误:
Running "flutter pub get" in drawer2...
Error on line 44, column 5 of pubspec.yaml: Expected a key while parsing a block mapping.
╷
44 │ assets :
│ ^
╵
Oops; flutter has exited unexpectedly.
Sending crash report to Google.
Crash report sent (report ID: 7f0c2ad768060692)
Crash report written to C:\Users\Mohamed bh\Desktop\files\flutter operations\drawer2\flutter_06.log;
please let us know at https://github.com/flutter/flutter/issues.
//我的pubspec.yaml代码
Flutter :
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets :
- assets/
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
Running "flutter pub get" in drawer2...
Error on line 44, column 5 of pubspec.yaml: Expected a key while parsing a block mapping.
╷
44 │ assets :
│ ^
╵
Oops; flutter has exited unexpectedly.
Sending crash report to Google.
Crash report sent (report ID: 7f0c2ad768060692)
Crash report written to C:\Users\Mohamed bh\Desktop\files\flutter operations\drawer2\flutter_06.log;
please let us know at https://github.com/flutter/flutter/issues.
2条答案
按热度按时间vojdkbi01#
1.我已经在项目的根目录下创建了assets/images文件夹,并将icon.png和gplus.png图像文件放入其中。
1.然后我在pubspec.yaml文件中定义了图像资源,如下图x1c 0d1x
1.然后在项目中使用的图像如下
5kgi1eie2#
你应该尊重缩进,如果你添加或删除甚至一个空格,它都不会起作用,这是你应该做的:
最好的方法是从official documentation复制/传递它。