Flutter - Unable to load asset on first load only

感情迁移 提交于 2021-01-29 03:50:41

问题


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): ══╡ 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.

What could be the issue?

Note:

  • flutter doctor states everything's fine
  • flutter version: v1.9.1+hotfix.2

回答1:


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

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


来源:https://stackoverflow.com/questions/58578979/flutter-unable-to-load-asset-on-first-load-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!