Search code examples
imageflutterdartcachingimage-compression

Flutter: How to compress network image


I want to implement image compress with cached_network_image but I don't know how to manage both of them at a same time. How do I build my own compressed network image widget in flutter?


Solution

  • We can do the same with cached_network_image as they've added some properties to manage the caching of images at the disk or memory level.

    The properties are:

    • cacheManager → BaseCacheManager?

    Option to use cache manager with other settings

    • maxHeightDiskCache → int?

    Will resize the image and store the resized image in the disk cache.

    • maxWidthDiskCache → int?

    Will resize the image and store the resized image in the disk cache.

    • memCacheHeight → int?

    Will resize the image in memory to have a certain height using ResizeImage

    • memCacheWidth → int?

    Will resize the image in memory to have a certain width using ResizeImage

    As mentioned in API documentation https://pub.dev/documentation/cached_network_image/latest/cached_network_image/CachedNetworkImage-class.html

    Other than these we've height and width constraints!