FlutterError: Unable to load asset

后端 未结 22 3370
死守一世寂寞
死守一世寂寞 2020-11-30 10:31

This is the folder structure of my app

.idea
.vscode
android
build
fonts
 Oxygen-Bold.tff
 Oxygen-Light.tff
 Oxygen-Regular.tff
images
 pizza0.png
 pizza1.pn         


        
22条回答
  •  孤城傲影
    2020-11-30 11:12

    I also had this problem. I think there is a bug in the way Flutter caches images. My guess is that when you first attempted to load pizza0.png, it wasn't available, and Flutter has cached this failed result. Then, even after adding the correct image, Flutter still assumes it isn't available.

    This is all guess-work, based on the fact that I had the same problem, and calling this once on app start fixed the problem for me:

    imageCache.clear();
    

    This clears the image cache, meaning that Flutter will then attempt to load the images fresh rather than search the cache.

    PS I've also found that you need to call this whenever you change any existing images, for the same reason - Flutter will load the old cached version. The alternative is to rename the image.

提交回复
热议问题