6

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
2
  • Have you tried looking at this? Commented Oct 27, 2019 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/...) Commented Oct 27, 2019 at 11:39

1 Answer 1

9

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

final img = Image.file(File(imageFilePath));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.