A flutter library for loading images from network, resizing as per container size and caching while being memory sensitive.

Overview

Optimized Cached Image

pub package

A flutter library for loading images from network, resizing and caching them for memory sensitivity. This resizes and stores the images in cache based on parent container constraints and hence loads images of lower size into memory. This is heavily inspired by cached_network_image library.

This library exposes two classes for loading images

  • OptimizedCacheImage which is a 1:1 mapping of CachedNetworkImage.
  • OptimizedCacheImageProvider which is a mapping of CachedNetworkImageProvider.

How to use

The OptimizedCacheImage can be used directly or through the ImageProvider. Both the OptimizedCacheImage as OptimizedCacheImageProvider have minimal support for web. It currently doesn't include caching.

With a placeholder:

OptimizedCacheImage(
        imageUrl: "http://via.placeholder.com/350x150",
        placeholder: (context, url) => CircularProgressIndicator(),
        errorWidget: (context, url, error) => Icon(Icons.error),
     ),

Or with a progress indicator:

OptimizedCacheImage(
       imageUrl: "http://via.placeholder.com/350x150",
       progressIndicatorBuilder: (context, url, downloadProgress) =>
               CircularProgressIndicator(value: downloadProgress.progress),
       errorWidget: (context, url, error) => Icon(Icons.error),
    ),
Image(image: OptimizedCacheImageProvider(url))

When you want to have both the placeholder functionality and want to get the imageprovider to use in another widget you can provide an imageBuilder:

OptimizedCacheImage(
  imageUrl: "http://via.placeholder.com/200x150",
  imageBuilder: (context, imageProvider) => Container(
    decoration: BoxDecoration(
      image: DecorationImage(
          image: imageProvider,
          fit: BoxFit.cover,
          colorFilter:
              ColorFilter.mode(Colors.red, BlendMode.colorBurn)),
    ),
  ),
  placeholder: (context, url) => CircularProgressIndicator(),
  errorWidget: (context, url, error) => Icon(Icons.error),
),

Handling Gifs

OCI uses Flutter Image Compress as the compression library, while being memory efficient this library doesn't provide out of box support for gifs, however it does allow compressing to webp. Hence all gifs are compressed to webp format beginning 2.0.2-alpha.

How it works

The optimized cached network images stores and retrieves files using the flutter_cache_manager.

FAQ

My app crashes when the image loading failed. (I know, this is not really a question.)

Does it really crash though? The debugger might pause, as the Dart VM doesn't recognize it as a caught exception; the console might print errors; even your crash reporting tool might report it (I know, that really sucks). However, does it really crash? Probably everything is just running fine. If you really get an app crashes you are fine to report an issue, but do that with a small example so we can reproduce that crash.

Comments
  • Support new flutter_cache_manager 2.x

    Support new flutter_cache_manager 2.x

    Thank you for the lib, it's saved me from the crash of loading a lot images, but the lib using flutter_cache_manager 1.x, it's good if have a branch support flutter_cache_manager 2.x, because it's conflict with some packages I used in the app.

    Thank you

    done 
    opened by winterdl 16
  • A resource failed to call close/release.

    A resource failed to call close/release.

    Thx, awesome lib! But I frequently see log message A resource failed to call close when I scroll thru list of items with OptimizedCacheImage

    I see places where it can happen:

    1. BaseCacheManager.getFileStream creates StreamController which is never release/closed
    2. ImageCacheManager.getFileStream - same

    I use optimized_cached_image: ^0.1.13 and heres Flutter doctor:

    doctor --verbose
    [✓] Flutter (Channel stable, v1.17.1, on Mac OS X 10.15.2 19C57, locale en-GB)
        • Flutter version 1.17.1 at /Users/zamahaka/Library/flutter
        • Framework revision f7a6a7906b (3 weeks ago), 2020-05-12 18:39:00 -0700
        • Engine revision 6bc433c6b6
        • Dart version 2.8.2
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
        • Android SDK at /Users/zamahaka/Library/Android/sdk
        • Platform android-29, build-tools 29.0.2
        • ANDROID_HOME = /Users/zamahaka/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 11.4)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 11.4, Build version 11E146
        • CocoaPods version 1.8.4
    
    [✓] Android Studio
        • Android Studio at /Applications/Android Studio 4.1 Preview.app/Contents
        • Flutter plugin version 45.0.2
        • Dart plugin version 193.6911.31
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    
    [✓] Android Studio (version 3.6)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin version 45.1.1
        • Dart plugin version 192.7761
        • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    
    [✓] Connected device (1 available)
        • Pixel 4 • 192.168.1.11:5555 • android-arm64 • Android 10 (API 29)
    
    • No issues found!
    
    opened by zamahaka 9
  • Support nullsafety

    Support nullsafety

    Hi,

    Can you update pack support nullsafety?

    Because optimized_cached_image >=2.0.0-dev.1 depends on octo_image ^0.3.0 and cached_network_image 3.0.0-nullsafety depends on octo_image ^1.0.0-nullsafety, optimized_cached_image >=2.0.0-dev.1 is incompatible with cached_network_image 3.0.0-nullsafety. And because no versions of cached_network_image match >3.0.0-nullsafety <4.0.0, optimized_cached_image >=2.0.0-dev.1 is incompatible with cached_network_image ^3.0.0-nullsafety. So, because onedanang depends on both cached_network_image ^3.0.0-nullsafety and optimized_cached_image ^2.0.0-dev.2, version solving failed. pub get failed (1; So, because onedanang depends on both cached_network_image ^3.0.0-nullsafety and optimized_cached_image ^2.0.0-dev.2, version solving failed.)

    Thanks

    opened by onethao 8
  • Exception: Could not instantiate image codec.

    Exception: Could not instantiate image codec.

    I get this error while loading images using this plugin. The image is loading from the url, but when I close the app and open again then I get this error. The images are loaded and displaying properly but after closing and re-opening the app I get these error.

    Exception: Could not instantiate image codec.

    When the exception was thrown, this was the stack: #0 _futurize (dart:ui/painting.dart:4304:5) #1 instantiateImageCodec (dart:ui/painting.dart:1682:10) #2 PaintingBinding.instantiateImageCodec (package:flutter/src/painting/binding.dart:88:12) #3 FileImage._loadAsync (package:flutter/src/painting/image_provider.dart:653:24) ... Path: /data/user/0/appPackageName/cache/libCachedImageData/e65291e0-c273-11ea-918b-35fb95148e5f.jpg

    bug solved? 
    opened by amitjangid80 7
  • Outdated Path_provider dependency

    Outdated Path_provider dependency

    Hello, I got the following dependency issue.

    Because shared_preferences >=2.0.0 depends on shared_preferences_windows ^2.0.0 which depends on path_provider_windows ^2.0.0, shared_preferences >=2.0.0 requires path_provider_windows ^2.0.0.
    
    And because optimized_cached_image >=2.0.0-dev.1 depends on path_provider ^1.6.18 which depends on path_provider_windows ^0.0.4, shared_preferences >=2.0.0 is incompatible with optimized_cached_image >=2.0.0-dev.1.
    

    I think we just need to update the path_provider dependency

    opened by pumuckelo 5
  • The getter 'store' isn't defined for the class     'ImageCacheManager'.

    The getter 'store' isn't defined for the class 'ImageCacheManager'.

    ../packages/flutter_optimized_cached_image/lib/image_cache_manager.dart:75:36: Error: The getter 'store' isn't defined for the class
    'ImageCacheManager'.
     - 'ImageCacheManager' is from 'package:optimized_cached_image/image_cache_manager.dart'
     ('../packages/flutter_optimized_cached_image/lib/image_cache_manager.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'store'.
          final orgCacheObject = await store.retrieveCacheData(parentUrl);
    

    [✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.7 19H2 darwin-x64, locale zh-Hans-CN) • Flutter version 1.22.5 at /Users/virs/.fvm/versions/1.22.5-stable • Framework revision 7891006299 (6 周前), 2020-12-10 11:54:40 -0800 • Engine revision ae90085a84 • Dart version 2.10.4 • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn

    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/virs/Library/Android/sdk • Platform android-30, build-tools 30.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) • All Android licenses accepted.

    [✓] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.3, Build version 12C33 • CocoaPods version 1.10.1

    [!] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

    [✓] VS Code (version 1.52.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.18.1

    [✓] Connected device (1 available) • iPhone 12 Pro Max (mobile) • AC7D42A0-6D02-434F-9BCB-F617A1AEFD6F • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)

    opened by virskor 5
  • Memory Leak occurs when using ImageBuilder

    Memory Leak occurs when using ImageBuilder

    • no cacheExtent, no use imageBuilder 3333

    • cacheExtent: height * 2, no use imageBuilder 2222

    • no cacheExtent, use imageBuilder 4444

    • cacheExtent: height * 2, use imageBuilder 1111

    Thanks for making a nice library! When I use imageBuilder I get an error where the memory is not released properly.

      List<double> _height = List<double>.filled(999, 0);
    
      @override
      Widget build(BuildContext context) {
        final width = MediaQuery.of(context).size.height;
        final height = MediaQuery.of(context).size.height;
        return Scaffold(
          body: ListView.builder(
            itemCount: imgs2.length,
            // cacheExtent: height * 2,
            itemBuilder: (context, index) {
              return OptimizedCacheImage(
                imageUrl: imgs2[index],
                fit: BoxFit.cover,
                imageBuilder: (context, imageProvider) {
                  Image imageView = Image(
                    image: imageProvider,
                  );
                  if (_height[index] == 0) {
                    ImageStream stream =
                        imageView.image.resolve(ImageConfiguration());
                    stream.addListener(
                        ImageStreamListener((ImageInfo info, bool synchronousCall) {
                      var myImage = info.image;
                      Size size =
                          Size(myImage.width.toDouble(), myImage.height.toDouble());
                      _height[index] = width / size.aspectRatio;
                    }));
                  }
                  return imageView;
                },
                progressIndicatorBuilder: (context, string, progress) {
                  return SizedBox(
                    height: 300,
                    child: Center(
                      child: SizedBox(
                        child: CircularProgressIndicator(value: progress.progress),
                        width: 30,
                        height: 30,
                      ),
                    ),
                  );
                },
              );
            },
          ),
        );
      }
    
    [√] Flutter (Channel beta, 1.21.0-9.2.pre, on Microsoft Windows [Version 10.0.18362.1082], locale ko-KR)
        • Flutter version 1.21.0-9.2.pre at C:\Dev\flutter
        • Framework revision 81a45ec2e5 (4 weeks ago), 2020-08-27 14:14:33 -0700
        • Engine revision 20a9531835
        • Dart version 2.10.0 (build 2.10.0-7.3.beta)
    
    
    [√] Android toolchain - develop for Android devices (Android SDK version 30.0.0) 
        • Android SDK at F:\android-sdk
        • Platform android-30, build-tools 30.0.0
        • ANDROID_HOME = F:\android-sdk
        • Java binary at: F:\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    
    [√] Android Studio (version 4.0)
        • Android Studio at F:\Android\Android Studio
        • Flutter plugin version 47.1.2
        • Dart plugin version 193.7361
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    
    [√] VS Code (version 1.49.1)
        • VS Code at C:\Users\\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.14.1
    
    [√] Connected device (4 available)
        • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
        • Web Server (web)                   • web-server    • web-javascript • Flutter Tools
        • Chrome (web)                       • chrome        • web-javascript • Google Chrome 85.0.4183.102
        • Edge (web)                         • edge          • web-javascript • Microsoft Edge 85.0.564.51
    
    • No issues found!
    

    Full source code: https://github.com/violet-dev/ocimmmmmmmmmmmmm/blob/master/lib/main.dart (images is sensational)

    bug In Progress 
    opened by violet-dev 5
  • Issue after updating with the flutter_image_compress dependency

    Issue after updating with the flutter_image_compress dependency

    After updating from 0.1.13 to 0.1.14, the flutter_image_compress dependency also seemed to update from 0.6.8 to 0.7.0. Trying to compile, I get this error message:

    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.6.8\android\src\main\kotlin\com\example\flutterimagecompress\FlutterImageCompressPlugin.kt: (15, 7): Redeclaration: FlutterImageCompressPlugin
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.6.8\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressFileHandler.kt: (18, 7): Redeclaration: CompressFileHandler
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.6.8\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressListHandler.kt: (14, 7): Redeclaration: CompressListHandler
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.6.8\android\src\main\kotlin\com\example\flutterimagecompress\core\ResultHandler.kt: (7, 16): Redeclaration: ResultHandler
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\FlutterImageCompressPlugin.kt: (17, 7): Redeclaration: FlutterImageCompressPlugin
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\FlutterImageCompressPlugin.kt: (25, 47): No value passed for parameter 'registrar'
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\FlutterImageCompressPlugin.kt: (26, 14): Unresolved reference: channel
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\FlutterImageCompressPlugin.kt: (27, 14): Unresolved reference: context
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\FlutterImageCompressPlugin.kt: (28, 14): Unresolved reference: channel
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\FlutterImageCompressPlugin.kt: (44, 70): Type mismatch: inferred type is Context but PluginRegistry.Registrar was expected
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\FlutterImageCompressPlugin.kt: (45, 70): Type mismatch: inferred type is Context but PluginRegistry.Registrar was expected
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\FlutterImageCompressPlugin.kt: (46, 87): Type mismatch: inferred type is Context but PluginRegistry.Registrar was expected
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressFileHandler.kt: (14, 7): Redeclaration: CompressFileHandler
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressFileHandler.kt: (17, 5): Unresolved reference: threadPool
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressFileHandler.kt: (65, 5): Unresolved reference: threadPool
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressListHandler.kt: (13, 7): Redeclaration: CompressListHandler
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressListHandler.kt: (16, 5): Unresolved reference: threadPool
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\ResultHandler.kt: (9, 16): Redeclaration: ResultHandler
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':flutter_image_compress:compileDebugKotlin'.
    > Compilation error. See log for more details
    

    After trying to manually delete the old package versions from .pub-cache, I get this:

    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressFileHandler.kt: (7, 48): Unresolved reference: log
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressFileHandler.kt: (32, 9): Unresolved reference: log
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressFileHandler.kt: (91, 9): Unresolved reference: log
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressListHandler.kt: (8, 48): Unresolved reference: log
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressListHandler.kt: (39, 9): Unresolved reference: log
    e: C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_image_compress-0.7.0\android\src\main\kotlin\com\example\flutterimagecompress\core\CompressListHandler.kt: (51, 9): Unresolved reference: log
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':flutter_image_compress:compileDebugKotlin'.
    > Compilation error. See log for more details
    

    Any idea what's going wrong? For now I've reverted the versions and it launches fine. My flutter doctor:

    Doctor summary (to see all details, run flutter doctor -v):
    [√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [Version 10.0.19041.388], locale en-AU)
    
    [√] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc4)
    [√] Android Studio (version 4.0)
    [√] VS Code (version 1.45.1)
    [√] Connected device (1 available)
    
    • No issues found!
    
    bug 
    opened by xJon 5
  • Image doesn't load when file in cache is unavailable

    Image doesn't load when file in cache is unavailable

    For some reason, from time to time, one or more files in cache get invalidated / corrupted and while it doesn't crash the app, the image container remains empty. The thrown exception is printed onto the console:

    Here is the error for your reference:

    Bad state: LocalFile: '/data/user/0/***/cache/libCachedImageData/****-d018-11ea-9ac9-19b2fc1cd3e3.jpg' is empty and cannot be loaded as an image.

    When the exception was thrown, this was the stack: 
          FileImage._loadAsync (package:flutter/src/painting/image_provider.dart:859:7)
    <asynchronous suspension>
          FileImage.load (package:flutter/src/painting/image_provider.dart:843:14)
          ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
          ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:359:22) 
    

    Similar error was encountered by people using a similar package and was recently fixed. Please look here

    Hoping for a quick fix / solution

    opened by dev-kasibhatla 5
  • Resize src image to match widget rect

    Resize src image to match widget rect

    Hi @humblerookie,

    Im Android dev and currently investigating Flutter for further migration on production. And faced a problem with large images on my project that I've been doing. The problem is that images with high res are slowing down the Grid widget when scrolling.

    Here my changes those I would like to add:

    1. Resize source image if it is bigger then widget Constraints;
    2. Add sample with the Grid widget;
    3. Small optimization of the OptimizedCacheImage.

    With the changes Images behave quite good. And I see next point to improve after I checkout your branch.

    There are duplicate code of transformer classes like ResizeImageCacheManager and DefaultImageTransformer.

    Implement LRU cache with the Expando api. I done something similar on Android but stuck on Flutter but I'm not exactly understanding it at the record pace.

    Some optimization of the OptimizedCacheImage. I would prefer moving url transformation to the appropriate cache manager.

    Thank you

    opened by vscmaster 5
  • Unhandled Exception: FileSystemException: Cannot retrieve length of file

    Unhandled Exception: FileSystemException: Cannot retrieve length of file

    E/flutter (18091): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: FileSystemException: Cannot retrieve length of file, path = '/data/user/0/com.example.music_taming/cache/libCachedImageData/5ee35fd0-9142-11ea-ed86-8791e4bc3e42_tmp.jpg' (OS Error: No such file or directory, errno = 2)
    E/flutter (18091): #0      _File.throwIfError  (dart:io/file_impl.dart:645:7)
    E/flutter (18091): #1      _File.lengthSync  (dart:io/file_impl.dart:387:5)
    E/flutter (18091): #2      DefaultImageTransformer._scaleImageFile
    E/flutter (18091): <asynchronous suspension>
    E/flutter (18091): #3      DefaultImageTransformer.transform
    E/flutter (18091): #4      ImageCacheManager.getFileStream.<anonymous closure>
    E/flutter (18091): #5      _rootRunUnary  (dart:async/zone.dart:1192:38)
    E/flutter (18091): #6      _CustomZone.runUnary  (dart:async/zone.dart:1085:19)
    E/flutter (18091): #7      _CustomZone.runUnaryGuarded  (dart:async/zone.dart:987:7)
    E/flutter (18091): #8      _BufferingStreamSubscription._sendData  (dart:async/stream_impl.dart:339:11)
    E/flutter (18091): #9      _DelayedData.perform  (dart:async/stream_impl.dart:594:14)
    E/flutter (18091): #10     _StreamImplEvents.handleNext  (dart:async/stream_impl.dart:710:11)
    E/flutter (18091): #11     _PendingEvents.schedule.<anonymous closure>  (dart:async/stream_impl.dart:670:7)
    E/flutter (18091): #12     _rootRun  (dart:async/zone.dart:1180:38)
    E/flutter (18091): #13     _CustomZone.run  (dart:async/zone.dart:1077:19)
    E/flutter (18091): #14     _CustomZone.runGuarded  (dart:async/zone.dart:979:7)
    E/flutter (18091): #15     _CustomZone.bindCallbackGuarded.<anonymous closure>  (dart:async/zone.dart:1019:23)
    E/flutter (18091): #16     _rootRun  (dart:async/zone.dart:1184:13)
    E/flutter (18091): #17     _CustomZone.run  (dart:async/zone.dart:1077:19)
    E/flutter (18091): #18     _CustomZone.runGuarded  (dart:async/zone.dart:979:7)
    E/flutter (18091): #19     _CustomZone.bindCallbackGuarded.<anonymous closure>  (dart:async/zone.dart:1019:23)
    E/flutter (18091): #20     _microtaskLoop  (dart:async/schedule_microtask.dart:43:21)
    E/flutter (18091): #21     _startMicrotaskLoop  (dart:async/schedule_microtask.dart:52:5)
    

    Debug mode pointed to resizedFile.lengthSync() in _scaleImageFile

    Future<FileInfo> _scaleImageFile(FileInfo info, int width, int height) async {
      File file = info.file;
      if (file.existsSync()) {
        String extension = p.extension(file.path) ?? '';
        final format = _compressionFormats[extension] ?? CompressFormat.png;
        final tmpFile = getTempFile(file, format);
        final srcSize = file.lengthSync();
        final screen = window.physicalSize;
        File resizedFile = await FlutterImageCompress.compressAndGetFile(
            file.path, tmpFile.path,
            minWidth: width ?? screen.width.toInt(),
            minHeight: height ?? screen.height.toInt(),
            format: format);
        if (resizedFile.lengthSync() < srcSize) {
          resizedFile.renameSync(file.path);
        } else {
          resizedFile.deleteSync();
        }
      }
      return info;
    }
    
    opened by Tizoner 5
  • iOS crazy memory usage

    iOS crazy memory usage

    Hello,

    Thank you so much for this library, first and foremost. It resolved some issues we were having with memory. But we are not very experienced with dart/flutter. But Android was very happy with this change.

    Then we tested on iOS and just showing 3 photos crashed the app when interacting with the UI (scrolling, etc.). So we took a heap snapshot with the memory page and noticed that regardless of how we configured the image widget in this library, each _Image instance was taking up 62MB of memory! This is regardless of the image or how we were processing it with Azure CDN.

    Here is the code that we were using, and if I just use Image.network instead of the library in iOS, the memory issues go away.

    optimizedCacheImage(MediaEntry entry) {
      if (entry.isUploading) return const Icon(Icons.upload);
    
      return Image.network(entry.downloadUrl,
          cacheWidth: 50,
          cacheHeight: 50,
          errorBuilder: (context, error, stackTrace) => const Icon(Icons.error));
    
      // var optimizedCacheImage = OptimizedCacheImage(
      //     memCacheHeight: 50,
      //     memCacheWidth: 50,
      //     maxWidthDiskCache: 50,
      //     maxHeightDiskCache: 50,
      //     imageUrl: entry.downloadUrl,
      //     placeholder: (context, url) => const Icon(Icons.cloud_sync_outlined),
      //     // progressIndicatorBuilder: (context, url, downloadProgress) =>
      //     //     CircularProgressIndicator(value: downloadProgress.progress),
      //     errorWidget: (context, url, error) {
      //       developer.log(error.toString(), name: 'optimizedCacheImage');
      //       return entry.isUploading
      //           ? const Icon(Icons.upload)
      //           : const Icon(Icons.error);
      //     });
      // return optimizedCacheImage;
    }
    

    Could I get some help understanding what we might be doing wrong, because again, this library works wonderfully in Android. Thank you!

    opened by jakehockey10 1
  • Bad State: Stream has already been listened to.

    Bad State: Stream has already been listened to.

    I'm running into the error: Bad State: Stream has already been listened to. when attempting to view an image after the first build. It occurs in the _loadAsync method of _image_provider_io.dart. I was wondering how to diagnose this and how to fix it. Could I get some help getting pointed in the right direction? It seems to behave slightly better if I make the following changes:

    image

    But I'm not sure if this is appropriate, and I have to leave the page and come back to get the image widget to "try again."

    Not sure if it is related or not, but if there are "enough" widgets, I can get the app to throw an out-of-memory exception as well. This current test was putting ~80 image widgets into a GridView.

    opened by jakehockey10 0
  • Small images have low quality

    Small images have low quality

    Hello,

    I really liked this package, it improved a lot the time for image display on my app. However, I'm having an issue when the images are small. As you can see the quality is extremely low:

    Screenshot_20220603-161101 Screenshot_20220603-161142

    I tried using the filterQuality param for the OptimizedCacheImage widget and manually setting the width and height to be higher than its parent size, but none of these worked.

    Is there a way to control the quality on those cases?

    Thanks in advance.

    opened by getpoucher 5
  • Show a gif that does not have the .gif extension

    Show a gif that does not have the .gif extension

    The backend sends me gif urls but the urls don't have any extension. Unfortunately, this package does not detect that it is a gif and fails to show it.

    One solution would be for the package to add a new field to the constructor to explicitly say that the url is a gif. Or is there a different approach I can take?

    Here is a sample gif: https://ceras-rewards-content-dev.s3.amazonaws.com/temp/fb18bae1-47a9-4bee-9dd5-592312521b9e/89da61d7220e41eaa80d3f1de2043a0f

    opened by kaciula 0
  • errorWidget param doesn't works

    errorWidget param doesn't works

    Hi guys,

    I'm using Flutter 2.8.1 and optimized_cached_image 3.0.0. I use the package in order to show the profile pic of my users.

    Some profile pics of my users are corrupted and the "errorWidget" param doesn't works (it seems that ). I tried with cached_network_image 3.2.0 and it works.

    How can I handle it?

    Thank you.

    opened by DavideM12 0
Releases(v3.0.0)
Owner
Anvith Bhat
Droid nut
Anvith Bhat
Memory Cache is simple, fast and global in-memory cache with CRUD features.

Memory Cache Memory Cache is simple, fast and global in-memory cache. Features Create, read, update, delete and invalidate cache. Expirable Cache Gett

Gökberk Bardakçı 6 Dec 25, 2022
Package to select layout per orientation or device size like mobile vs tablet layouts or portrait vs landscape

proxy_layout Package to select layout per orientation or device size like mobile vs tablet layouts or portrait vs landscape Usage You have two widgets

Jimmy Aumard 8 Apr 18, 2021
System info plus - A Flutter plugin to get device Random Access Memory (RAM) size

system_info_plus A Flutter plugin to get device Random Access Memory (RAM) size.

Sebghatullah Yusuf 2 Aug 21, 2022
Stories like in Instagram, each story can include multiple images and videos. Package supports video, titles, preliminary caching.

flutter_instagram_stories A Flutter package for displaying stories just like Whatsapp & Instagram. Built-in groups (multiple stories with one icon), c

Alex Awaik 125 Dec 9, 2022
Esizer - A Flutter package provide responsive, dynamic, configurable size for each device screen size

ESizer A Flutter package provide responsive, dynamic, configurable size for each

Extreme Vietnam Public 1 Feb 15, 2022
A package that gives us a modern way to show animated border as a placeholder while loading our widget with easy customization and ready to use.

A package that gives us a modern way to show animated border as a placeholder while loading our widget with easy customization and ready to use.

Mohit Chauhan 8 Oct 3, 2022
An app to pick, upload and display images from camera and gallery with size and extension constraints.

image_uploader A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

Ehmad Saeed⚡ 4 Mar 7, 2022
In this repo you will see how to pick images from the image library and also, see how to store the selected images on Firebase.

flutterimageapp Flutter Tutorial - Upload Images using Firebase Storage. Flutter Tutorial - Upload Images using Firebase Storage Video series can be w

Whatsupcoders 60 Nov 4, 2022
A Dart/Flutter package to perform network calls. It uses Isolates to perform network calls on Dart VM environments and WebWorkers on Web.

ArDriveHTTP ArDriveHTTP is a package to perform network calls for ArDrive Web. It uses Isolates to perform network calls on Dart VM environments and W

AR.IO 2 Dec 15, 2022
Dart / Flutter package that allows discovering network devices in local network (LAN).

lan_scanner Dart / Flutter package that allows discovering network devices in local network (LAN). Note: This library is intended to be used on Class

null 12 Dec 9, 2022
Flutter-pinbox - UI for enter a PIN on flutter/dart, one digit per textField box.

flutter-pinbox This is a library for enter a PIN on flutter/dart. You can enter one digit per textField box. The detail The library locate at path lib

null 2 Feb 26, 2022
Apply values per media breakpoints. Breakpoints are similar to the breakpoints used in bootstrap css framework.

Apply values per media breakpoints. Breakpoints are similar to the breakpoints used in bootstrap css framework.

Glenford Williams 4 Mar 26, 2021
Data Migrator - provide a universal translator for data by being portable, diverse, and efficient in migrating and converting data across discrete schemas

Data Migrator - provide a universal translator for data by being portable, diverse, and efficient in migrating and converting data across discrete schemas

Tanner Meade 77 Jan 2, 2023
Dart-ci-tools - A container image with flutter and various CI tools.

dart-ci-tools Container built from the official Dart image, with various CI tools written in Dart. Project Notes There are tools available to: deploy

null 1 Jan 12, 2022
A container image with flutter and various CI tools.

flutter-ci-tools A Docker container built from the cirrusci/flutter image, with various CI tools. Project Notes With the available tools you can: depl

null 1 Jan 12, 2022
A project made for the ECV Digital 2022. 🌐 The goal being to make a Flutter application to connect, register and display information of a given API.👨🏼🔧

not_netflix A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if t

QUENEL Laurent 2 May 7, 2022
A Funtioning basic Clock UI APP with extra functionalities such as displaying thecurrent time location being used and checking time for other timezones simultaneosly.

clock_UI A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Anjola Favour Ayomikun 0 Dec 28, 2021
Animation (front and Back Container)

Flippable_Box A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Rasul Ramixanov 1 Jan 5, 2022