簡體   English   中英

Flutter 錯誤圖像:無法加載資產

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM