未加载颤动图像(例外:解析图像编解码器)

问题描述 投票:3回答:4

当我尝试运行图像资产没有正确加载时,我得到一个例外:

抛出以下断言解析图像编解码器:无法加载资产:/ images / p8.png`

几周前它正在运作,现在它停止了。我试图从不同的PC和Mac运行(使用模拟器),但仍然无法加载图像。而是正确加载字体。

这就是我加载图像的方式,它们是在GridView中呈现的。下面是代码:

return new Expanded(
      child: new GridView.count(
          crossAxisCount: 2,
          padding: const EdgeInsets.fromLTRB(16.0, 25.0, 16.0, 4.0),
          children: <Widget>[
            new MaterialButton(
              onPressed: () {
                Navigator.of(context).pushNamed('/biliardo');
              },
              child: new Column(
                children: <Widget>[
                  new Image(
                    //parte importante, definire gli asset per trovarli più velocemnte
                    //si inseriscono nel pubspec.yaml
                    image: new AssetImage('/images/p8.png'),
                    height: 100.0,
                    width: 100.0,
                  ),
                  new Text(
                    "BILIARDO",
                    style: new TextStyle(
                      color: (darkTheme) ? Colors.blue : Colors.black,
                    ),
                  )
                ],
              ),
            ),

            .....

    );

pubsec.yaml文件代码:

flutter:
  uses-material-design: true
  assets:
    - images/emptyBall.png
    - images/p1.png
    - images/p2.png
    - images/p3.png
    - images/p4.png
    - images/p5.png
    - images/p6.png
    - images/p7.png
    - images/p8.png
    - images/p9.png
    - images/p10.png
    - images/p11.png
    - images/p12.png
    - images/p13.png
    - images/p14.png
    - images/p15.png
    - images/basket.png
    - images/volley.png
    - images/tennis.png
    - images/rugby.png
    - images/numbers.png
  fonts:
    - family: ShotClock
      fonts:
        - asset: utils/ShotClock.ttf

日志

扑动分析

Analyzing D:\Android\AndroidStudioProjects\flutter_app...
No issues found!
Ran in 5.2s

扑-v跑

https://docs.google.com/document/d/133Z7029VGJXBDCYLgCrj09F9cLbvIQQ5X8yBS4pPC7I/edit?usp=sharing

颤抖的医生

扑医生-v

[√] Flutter (Channel beta, v0.3.1, on Microsoft Windows [Versione 10.0.16299.371], locale it-IT)
    • Flutter version 0.3.1 at C:\Program Files\Flutter\flutter
    • Framework revision 12bbaba9ae (12 days ago), 2018-04-19 23:36:15 -0700
    • Engine revision 09d05a3891
    • Dart version 2.0.0-dev.48.0.flutter-fe606f890b

[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at C:\Users\Zanini\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
    • All Android licenses accepted.

[√] Android Studio (version 3.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 24.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)

[√] Connected devices (1 available)
    • Nexus 5X • 01cde5e7db8d4c14 • android-arm64 • Android 8.1.0 (API 27)

• No issues found!
image dart flutter codec
4个回答
9
投票

在你的png路径中摆脱领先的/。它应该是images/p8.png

另外,考虑使用更干净的Image.asset构造函数,例如:

new Image.asset('images/p8.png', width: 100.0, height: 100.0)


3
投票

在所有图像路径中正确添加“/”

在Android Studio中

工具 - >颤振 - >颤动清洁


2
投票

需要注意的一点是'assets:'标记必须使用'flutter:'标记正确缩进,但它只会在加载资源时偶尔抛出一个错误。所以这不起作用:

flutter: 
assets:
    - images/

但这会:

flutter: 
  assets:
    - images/

1
投票

使用新的flutter版本,您还可以将文件夹放在pubspec.yaml中,而不仅仅是文件

flutter:
  uses-material-design: true
  assets:
    - images/
© www.soinside.com 2019 - 2024. All rights reserved.