Flutter_cached_network_image: Image resizing causes app to stuck.

Created on 17 Mar 2021  路  5Comments  路  Source: Baseflow/flutter_cached_network_image

I use cached_network_image-2.5.1 to load images in ListView. After setting maxWidth and maxHeight, there will be stuck in the sliding ListView.

OctoImage(
  image: CachedNetworkImageProvider(
    url,
    maxWidth: w.toInt(),
    maxHeight: h.toInt(),
  ),
  fit: BoxFit.cover,
)
bug

Most helpful comment

This behavior is very important for my use-case. I actually have to do a workaround to not store the large image at all, and exclusively store the scaled image.

I work with a third party API that I don't control, it provides image links that I don't control, that are much larger than they need to be, so I have to cache them to save my user's bandwidth.

If cached at full size, the number of images I need to cache would take up massive amounts of storage.

All 5 comments

I am also getting these problem,
any solution please,

The maxWidth and maxHeight properties on the CachedNetworkImageProvider resize the image and store the resized image on disk. It looks like the copyResize function that is used blocks the UI thread. I'll have to look into it, but I didn't quickly find a better solution that is also cross platform.
https://github.com/Baseflow/flutter_cache_manager/blob/develop/flutter_cache_manager/lib/src/cache_managers/image_cache_manager.dart#L85

If you set memCacheWidth and memCacheHeight on OctoImage the image is also scaled, but the scaled version is not stored on disk. I do think that this method is more efficient though.

I'm thinking of removing the option for storing scaled images on disk.

This behavior is very important for my use-case. I actually have to do a workaround to not store the large image at all, and exclusively store the scaled image.

I work with a third party API that I don't control, it provides image links that I don't control, that are much larger than they need to be, so I have to cache them to save my user's bandwidth.

If cached at full size, the number of images I need to cache would take up massive amounts of storage.

Also running into this issue.
As a test, try pulling the images from this feed and display in a ListView (they are larger images):
https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss

I'm doing this, scaling down to 150x150 and lagging out, ui is totally unresponsive.
I'll add some code later, what I have is an absolute mess at the moment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anass-naoushi picture anass-naoushi  路  5Comments

Gavin-1991 picture Gavin-1991  路  6Comments

srburton picture srburton  路  6Comments

tolotrasamuel picture tolotrasamuel  路  6Comments

qq3144225600 picture qq3144225600  路  5Comments