Flutter Image.asset Mapping valu
2018-12-14 本文已影响78人
_海角_
Image控件即为图片控件。
Image控件有多种构造函数:
new Image,用于从ImageProvider获取图像。
new Image.network,用于从URL地址获取图像。
new Image.file,用于从File获取图像。
new Image.asset,用于使用key从AssetBundle获取图像。
上面三个很简单,第四个在使用的时候,一不小心就会报如下错误
Error on line 44, column 10 of pubspec.yaml: Mapping values are not allowed here. Did you miss a colon earlier?
assets:
^
Unable to reload your application because "flutter packages get" failed to update package dependencies.
Exception: pub get failed (65)
Image.asset 使用之前需要在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
assets:
- lib/image/
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
报错信息很朦胧,实际原因是: assets: 前面多了个空格 ,。。。。。