简体   繁体   English

Flutter 错误图像:无法加载资产

[英]Flutter Error IMAGE: Unable to load asset

I tried to get flutter pub get, tried several ways to add the image我尝试获取 flutter pub get,尝试了几种添加图像的方法

My pubspec.yaml我的 pubspec.yaml

flutter:
uses-material-design: true
assets:  
- assets/images/

Especific code in main.dart 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),
              )        
            ),  

Debug Console调试控制台

════════ 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

The hierarchy of folders:文件夹层次结构:

文件夹的层次结构

Indentations(spaces) are highly important in pubspec.yaml file.缩进(空格)在 pubspec.yaml 文件中非常重要。 Your issue is related to this.您的问题与此有关。 You can fix it like this:你可以像这样修复它:

flutter:
  uses-material-design: true
  assets:  
    - assets/images/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM