【问题标题】:Exception caught by image resource service, The following assertion was thrown resolving an image codec:图像资源服务捕获的异常,在解析图像编解码器时引发了以下断言:
【发布时间】:2019-10-27 04:04:34
【问题描述】:

我正在尝试将图像加载到滚动中,但每次由于错误而无法加载图像:

Exception caught by image resource service The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/jorge.png

当异常被抛出时,这是堆栈:

0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)

1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:464:44)

2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:449:14)
...

Image provider: AssetImage(bundle: null, name: "assets/images/jorge.png")

Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dd41f(), name: "assets/images/jorge.png", scale: 1.0)

(2) 图像资源服务捕获的异常

 Unable to load asset: assets/images/heitor.png

(3) 图像资源服务捕获的异常

 Unable to load asset: assets/images/john.png

 I/chatty  ( 8763): uid=10206(com.festapp.flutter_app_fest) identical 5 lines
 E/AccessibilityBridge( 8763): VirtualView node must not be the root node.


 flutter clean was used, besides exchanging images

 final User currentUser = User(
  id: 0,
  name: 'Current User',
  imageUrl: 'assets/images/greg.png'
);

//使用方法

final User Jorge = User(
  id: 1,
  name: 'Jorge',
   imageUrl: 'assets/images/jorge.png'
);

final User John= User(
   id: 2,
   name: 'John',
   imageUrl: 'assets/images/john.png'
); 

final User Heitor = User(
   id: 3,
   name: 'Heitor',
   imageUrl: 'assets/images/heitor.png'

); 最终用户 Gui = User( 编号:4, 名称:'桂', imageUrl: '资产/图像/heitor.png' );

以及图片用于:

return Padding(
              padding: EdgeInsets.all(10.0),
              child: Column(
                children: <Widget>[
                  CircleAvatar(
                    radius: 35.0,
                    backgroundImage: AssetImage(favorites[index].imageUrl),
                  ),
                  SizedBox(
                    height: 6.0,
                  ),
                  Text(favorites[index].name, style: TextStyle(
                    color: Colors.blueGrey,
                    fontSize: 16.0,
                    fontWeight: FontWeight.w600,
                  ),
                  ),
                ],
              ),
            );

图片资源服务捕获的异常

在解析图像编解码器时引发了以下断言:

Unable to load asset: assets/images/jorge.png

当异常被抛出时,这是堆栈:

0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)

1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:464:44)

2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:449:14)
...
 Image provider: AssetImage(bundle: null, name: "assets/images/jorge.png")
 Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dd41f(), name: "assets/images/jorge.png", scale: 1.0)

(2) 图像资源服务捕获的异常

Unable to load asset: assets/images/heitor.png

(3) 图像资源服务捕获的异常

Unable to load asset: assets/images/john.png

【问题讨论】:

    标签: flutter


    【解决方案1】:

    您的项目中似乎没有这些图像文件:

    • assets/images/jorge.png
    • assets/images/john.png
    • assets/images/heitor.png

    确保你正在做这些事情:

    • 在文件夹assets/images/中添加图片
    • 指定pubspec.yaml中的图片
    • 执行flutter packages get/点击Packages get from pubspec.yaml / 在任何 dart 文件中点击 Get dependencies
    • 使用Image.asset()AssetImage() 显示它们。

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题, 解决方案是停止 main.dart - 通过单击任务栏中给出的红色按钮 然后重新启动它。 有时,当您将其添加为新鲜时,它无法加载图像

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-08
      • 2019-12-24
      • 2022-01-04
      • 2019-03-09
      • 2022-10-04
      • 2021-06-07
      • 1970-01-01
      相关资源
      最近更新 更多