5

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 play 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
tomerpacific
  • 4,704
  • 13
  • 34
  • 52
HTMHell
  • 5,761
  • 5
  • 37
  • 79
  • Have you tried looking at [this](https://stackoverflow.com/questions/53659809/fluttererror-unable-to-load-asset)? – tomerpacific Oct 27 '19 at 11:36
  • @tomerpacific I'm not using a static asset, it's a file saved on the documents path (`/data/user/0/com.example.myapp/app_flutter/...`) – HTMHell Oct 27 '19 at 11:39

1 Answers1

7

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

final img = Image.file(File(imageFilePath));
Igor Kharakhordin
  • 9,185
  • 3
  • 40
  • 39