[英]Flutter Error IMAGE: Unable to load asset
我尝试获取 flutter pub get,尝试了几种添加图像的方法
我的 pubspec.yaml
flutter:
uses-material-design: true
assets:
- assets/images/
main.dart 中的具体代码
decoration: new BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/thermo.png'),
fit: BoxFit.fill,
),
color: Color.fromRGBO(78, 144, 30, 1),
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(30.0),
topRight: const Radius.circular(30.0),
bottomLeft: const Radius.circular(30.0),
bottomRight: const Radius.circular(30.0),
)
),
调试控制台
════════ Exception caught by image resource service ════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/thermo.png
When the exception was thrown, this was the stack
#0 PlatformAssetBundle.load
package:flutter/…/services/asset_bundle.dart:225
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync
package:flutter/…/painting/image_provider.dart:668
#2 AssetBundleImageProvider.load
package:flutter/…/painting/image_provider.dart:651
文件夹层次结构:
缩进(空格)在 pubspec.yaml 文件中非常重要。 您的问题与此有关。 你可以像这样修复它:
flutter:
uses-material-design: true
assets:
- assets/images/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.