Flutter-无法仅在首次加载时加载资产 [英] Flutter - Unable to load asset on first load only

查看:58
本文介绍了Flutter-无法仅在首次加载时加载资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将这样的图像加载到我的flutter应用程序中:

I load an image on my flutter app like this:

Image.asset(imageFilePath, fit: BoxFit.cover)

当我第一次在模拟器上运行应用程序时,出现以下异常:

When I run the app on the emulator on the first run I get the following exception:

I/flutter(7194):IM图像资源服务引起的异常提示╞════════════════════════════════════════════════════我/颤振(7194):抛出以下断言来解析图像编解码器:I/flutter(7194):无法加载资产:/data/user/0/com.example.myapp/app_flutter/888cba5135c38f7d.jpg ...

I/flutter ( 7194): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ I/flutter ( 7194): The following assertion was thrown resolving an image codec: I/flutter ( 7194): Unable to load asset: /data/user/0/com.example.myapp/app_flutter/888cba5135c38f7d.jpg ...

图像路径正确,并且文件存在.

The image path is correct, and the file exists.

如果我重新运行该应用程序(请单击按钮),则应用程序将毫无例外地加载,并且图像看起来还不错.

If I re-run the application (click the button), the application loads without the exception and the image appears just fine.

可能是什么问题?

注意:

  • flutter doctor 表示一切正常
  • flutter版本:v1.9.1 + hotfix.2

推荐答案

您是说您的文件不是资产,然后使用另一个Image构造函数:

You're saying that your file isn't asset, then use another Image constructor:

final img = Image.file(File(imageFilePath));

这篇关于Flutter-无法仅在首次加载时加载资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆