Flutter - Unable to load asset on first load only

2,759

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

final img = Image.file(File(imageFilePath));
Share:
2,759
HTMHell
Author by

HTMHell

Updated on December 15, 2022

Comments

  • HTMHell
    HTMHell over 1 year

    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