Git Product home page Git Product logo

humblerookie / optimized_cached_image Goto Github PK

View Code? Open in Web Editor NEW
80.0 6.0 42.0 433 KB

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

License: MIT License

Kotlin 0.14% Ruby 5.36% Swift 1.57% Objective-C 0.04% Dart 54.54% Shell 0.02% CMake 14.78% C++ 21.24% C 1.12% HTML 1.19%
flutter imagecaching imageloadinglibrary

optimized_cached_image's Introduction

Optimized Cached Image

pub package

❌❌ Important Update ❌❌

This library is no longer being maintained. When I started this library, it was meant to add memory performant extensions which could not be directly added into the parent library. Since then a lot has changed, the parent library has incorporated similar changes, perhaps with the exception of a trivial LayoutBuilder that auto detects image sizes. I feel like this is a good time to deprecate this library in favour of the parent.

Description

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.

optimized_cached_image's People

Contributors

bes89 avatar braginsm avatar britannio avatar humblerookie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

optimized_cached_image's Issues

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

Gif support

After switching from cached_network_image I found that gif-s aren't playing anymore. Flutter Image natively supports playing gif-s, it would be nice if this (otherwise really great!) package could support it as well.

Failures on ImageCacheManager using HttpStream

UPDATE: With HttpStream hanging up on .png and .cms image files and not displaying images with those extensions, with useHttpStream:false able to display them though it takes between 1-3 secs each.
Image rendering HttpStream is considerably faster when set to true.


Thank you for exposing the CacheManager as well (using the Optimized Cache Manager in app). Initialized with
ImageCacheManager.init(ImageCacheConfig(useHttpStream: true));
and read a few Lists of networks images (each with probably 50 images some cached already). My observations -
a) Response appeared quicker with Httpstream though I didn't measure it.
b) While viewing each list of images - running into failures - no image is displayed(I guess it's trying to switch from Cache to fetch from the Network). Able to hit the URL directly with no issues.
I'll do some more testing by increasing the default number of items that can be written to cache.
See attached logs -

I/flutter (28301): HttpException: No valid statuscode. Statuscode was 200
I/flutter (28301): CacheManager: Failed to download file from https://timesofindia.indiatimes.com/photo/74964829.cms?oci_width=0&oci_height=359 with error:
I/flutter (28301): HttpException: No valid statuscode. Statuscode was 200
W/System (28301): A resource failed to call close.

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

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!

Because optimized_cached_image >=2.0.0-dev.2 depends on sprintf ^6.0.0 and i18n_extension >=6.0.0 depends

Because optimized_cached_image >=2.0.0-dev.2 depends on sprintf ^6.0.0 and i18n_extension >=6.0.0 depends on sprintf ^7.0.0, optimized_cached_image >=2.0.0-dev.2 is incompatible with i18n_extension >=6.0.0.
And because flutter_quill >=6.1.6 depends on i18n_extension ^6.0.0, optimized_cached_image >=2.0.0-dev.2 is incompatible with flutter_quill >=6.1.6.
So, because tirin_app_flutter_mobx depends on both optimized_cached_image ^3.0.1 and flutter_quill ^6.2.2, version solving failed.

Jank when using 2.0.1

is anyone having a similar issue when using it in a ListView? CachedNetworkImage doesn't have this issue, neither did version 1.0.0.

Null-Safety support

I was wondering if you plan to support null-safety for this optimized_cached_image project?

Error after upgrading to v.2.0.1

I'm getting this error when I want to get the APK.

$ flutter build apk

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
A problem occurred configuring project ':flutter_image_compress'.       
> Could not resolve all artifacts for configuration ':flutter_image_compress:classpath'.
   > Could not download kotlin-compiler-embeddable.jar (org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.50)
      > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.3.50/kotlin-compiler-embeddable-1.3.50.jar'.
         > Read timed out                                               
   > Could not download kotlin-daemon-client.jar (org.jetbrains.kotlin:kotlin-daemon-client:1.3.50)
      > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-daemon-client/1.3.50/kotlin-daemon-client-1.3.50.jar'.
         > Read timed out                                               
   > Could not download kotlin-reflect.jar (org.jetbrains.kotlin:kotlin-reflect:1.3.50)
      > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.3.50/kotlin-reflect-1.3.50.jar'.
         > Read timed out                                               
   > Could not download kotlin-daemon-embeddable.jar (org.jetbrains.kotlin:kotlin-daemon-embeddable:1.3.50)
      > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-daemon-embeddable/1.3.50/kotlin-daemon-embeddable-1.3.50.jar'.
         > Read timed out                                               
> Could not get unknown property 'android' for project ':flutter_image_compress' of type org.gradle.api.Project.
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org                              
                                                                        
BUILD FAILED in 3m 20s   

Using Hero widget will cause image to reload

Please use this code snippet to reproduce this issue.

import 'package:optimized_cached_image/optimized_cached_image.dart';
import 'package:flutter/material.dart';

void main() => runApp(HeroApp());

class HeroApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Transition Demo',
      home: MainScreen(),
    );
  }
}

class MainScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    print("Rebuild");
    return Scaffold(
      appBar: AppBar(
        title: Text('Main Screen'),
      ),
      body: GestureDetector(
        child: Hero(
          tag: 'imageHero',
          child: OptimizedCacheImage(
            imageUrl:
                'https://i.picsum.photos/id/1/5616/3744.jpg?hmac=kKHwwU8s46oNettHKwJ24qOlIAsWN9d2TtsXDoCWWsQ',
            progressIndicatorBuilder: (context, url, progress) => Center(
              child: CircularProgressIndicator(
                value: progress.progress,
              ),
            ),
            errorWidget: (context, url, error) => Icon(Icons.error),
          ),
        ),
        onTap: () {
          Navigator.push(context, MaterialPageRoute(builder: (_) {
            return DetailScreen();
          }));
        },
      ),
    );
  }
}

class DetailScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GestureDetector(
        child: Center(
          child: Hero(
            tag: 'imageHero',
            child: OptimizedCacheImage(
              imageUrl:
                  'https://i.picsum.photos/id/1/5616/3744.jpg?hmac=kKHwwU8s46oNettHKwJ24qOlIAsWN9d2TtsXDoCWWsQ',
              progressIndicatorBuilder: (context, url, progress) => Center(
                child: CircularProgressIndicator(
                  value: progress.progress,
                ),
              ),
            ),
          ),
        ),
        onTap: () {
          Navigator.pop(context);
        },
      ),
    );
  }
}

Hero transition shouldn't cause the image to reload. The behavior should be similar to Image.network

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

When trying to build my project, I'm getting this error. When I look into the code, it's right. I can't find store declared anywhere in this package. In fact, it's only mentioned in this function. How do I get around this?

../../development/flutter/.pub-cache/hosted/pub.dartlang.org/optimized_cached_image-1.0.0/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' ('../../development/flutter/.pub-cache/hosted/pub.dartlang.org/optimized_cached_image-1.0.0/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);
    ^^^^^

Max cache size

Hello !

This is more a question than a bug report :)
What is the default max cache size and is it possible to modify it please ?

Regards

How to do zooming?

I have tested all the solutions i have found but the image doesn't go full-screen. It zooms in its boundaries.

Please add cancellation function

This is a high-performance plugin, but no cancellation function.
When a lot of image in a list view, and user scrolling it fast, a lot of network or file load will cause lag.
so, whould you thinking for add cancellation function please?
The cancellation function will bring amazing performance and load capacity!
and thank you!

Not Optimizing in some instances

UPDATE: Think I know what's contributing to the issue - only when I specify width: it doesn't compress the images. If I specify length: no image is displayed
OptimizedCacheImage(
imageUrl: widget.itemzs[index].originalimageurl,
width:300,
Also in my test example 8 images compress from 24.2 MB to 4.3 MB in memory which is awesome.

In my brief tests for OptimizedCacheImageProvider using your example image (second one) I didn't see a change in memory used. It used 7.3MB with both CachedNetworkImage and OptimizedCacheImageProvider. The example image for OptimizedCacheImage went down from 2.3MB to 278.2 KB which is terrific
.

Thanks for taking this initiative on - will be quite useful.
I used all three - a) OptimizedCacheImageProvider b) OptimizedCacheImage c) CachedNetworkImage
loading 8 network images - I am not seeing a change in the memory allocations between all three. I used Dart Observatory to compare the heap allocations and uninstalled the app between tests. They stay fairly constant in my case 23.7MB. Is there something that has to be implemented differently to get the optimized image into memory?

Using optimized_cache_image in a hero causes flickering in latest version

Hi @humblerookie,

I am using optmized_cache_image within a Hero widget to animate between two views. When I first used v1 of your package I noticed that the image would flicker during the animation. optmized_cache_image was trying to fetch a different sized version of the image during each frame of the animation which resulted in flickering and the placeholder appearing in some frames. I realised I hadn't set the height and width, so doing so fixed it. With version 2 of your package I have found the flickering is back and I can't work out what I have not set as the height and width fields are set. I hope that makes sense. The two videos below show the animation with v1 (before.mp4) and v2 (after.mp4) (slowed down to make it more obvious).

Do you have any idea or pointers as to where I can pinpoint the issue?

before.mp4
after.mp4

Many thanks.

Error: The getter 'reportImageChunkEvent' isn't defined for the class 'MultiImageStreamCompleter'

After updating to the version 1.0.0 Im getting the following error message, it also happens in version 0.1.15

Compiler message:
../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/optimized_cached_image-1.0.0/lib/image_provider/multi_image_stream_completer.dart:40:9: Error: The getter
'reportImageChunkEvent' isn't defined for the class 'MultiImageStreamCompleter'.
 - 'MultiImageStreamCompleter' is from 'package:optimized_cached_image/image_provider/multi_image_stream_completer.dart'
 ('../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/optimized_cached_image-1.0.0/lib/image_provider/multi_image_stream_completer.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'reportImageChunkEvent'.
        reportImageChunkEvent,   

This is the result of flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.5, on Mac OS X 10.15.5 19F101, locale en-US)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
 
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.48.0)
[✓] Connected device (1 available)

• No issues found!

Error when building on 2.0.1

flutter/.pub-cache/hosted/pub.dartlang.org/optimized_cached_image-2.0.1/lib/src/transformer/image_transformer.dart:83:23: Error: The class 'File' is abstract and can't be instantiated.
final scaleFile = File(destPath);
^^^^

The method 'existsSync' was called on null.

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'existsSync' was called on null.

This error is from here

File resizedFile = await FlutterImageCompress.compressAndGetFile(
    file.path, tmpFile.path,
    minWidth: minWidth, minHeight: minHeight, format: format);
if(resizedFile.existsSync()) {
  if (resizedFile.lengthSync() < srcSize) {
    resizedFile.renameSync(file.path);
  } else {
    resizedFile.deleteSync();
  }
}

Please do something about it.

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.

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

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.

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

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)
�[38;5;244mE/flutter (18091): #0      _File.throwIfError  (dart:io/file_impl.dart:645:7)�[39;49m
�[38;5;244mE/flutter (18091): #1      _File.lengthSync  (dart:io/file_impl.dart:387:5)�[39;49m
�[38;5;248mE/flutter (18091): #2      DefaultImageTransformer._scaleImageFile�[39;49m
E/flutter (18091): <asynchronous suspension>
�[38;5;248mE/flutter (18091): #3      DefaultImageTransformer.transform�[39;49m
�[38;5;248mE/flutter (18091): #4      ImageCacheManager.getFileStream.<anonymous closure>�[39;49m
�[38;5;244mE/flutter (18091): #5      _rootRunUnary  (dart:async/zone.dart:1192:38)�[39;49m
�[38;5;244mE/flutter (18091): #6      _CustomZone.runUnary  (dart:async/zone.dart:1085:19)�[39;49m
�[38;5;244mE/flutter (18091): #7      _CustomZone.runUnaryGuarded  (dart:async/zone.dart:987:7)�[39;49m
�[38;5;244mE/flutter (18091): #8      _BufferingStreamSubscription._sendData  (dart:async/stream_impl.dart:339:11)�[39;49m
�[38;5;244mE/flutter (18091): #9      _DelayedData.perform  (dart:async/stream_impl.dart:594:14)�[39;49m
�[38;5;244mE/flutter (18091): #10     _StreamImplEvents.handleNext  (dart:async/stream_impl.dart:710:11)�[39;49m
�[38;5;244mE/flutter (18091): #11     _PendingEvents.schedule.<anonymous closure>  (dart:async/stream_impl.dart:670:7)�[39;49m
�[38;5;244mE/flutter (18091): #12     _rootRun  (dart:async/zone.dart:1180:38)�[39;49m
�[38;5;244mE/flutter (18091): #13     _CustomZone.run  (dart:async/zone.dart:1077:19)�[39;49m
�[38;5;244mE/flutter (18091): #14     _CustomZone.runGuarded  (dart:async/zone.dart:979:7)�[39;49m
�[38;5;244mE/flutter (18091): #15     _CustomZone.bindCallbackGuarded.<anonymous closure>  (dart:async/zone.dart:1019:23)�[39;49m
�[38;5;244mE/flutter (18091): #16     _rootRun  (dart:async/zone.dart:1184:13)�[39;49m
�[38;5;244mE/flutter (18091): #17     _CustomZone.run  (dart:async/zone.dart:1077:19)�[39;49m
�[38;5;244mE/flutter (18091): #18     _CustomZone.runGuarded  (dart:async/zone.dart:979:7)�[39;49m
�[38;5;244mE/flutter (18091): #19     _CustomZone.bindCallbackGuarded.<anonymous closure>  (dart:async/zone.dart:1019:23)�[39;49m
�[38;5;244mE/flutter (18091): #20     _microtaskLoop  (dart:async/schedule_microtask.dart:43:21)�[39;49m
�[38;5;244mE/flutter (18091): #21     _startMicrotaskLoop  (dart:async/schedule_microtask.dart:52:5)�[39;49m

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;
}

Caching image at different sizes?

I'm downloading a full-size image then using OptimizedCacheImage to cache a downsized version but then when I want to view the full-size image it sees that the width and height are different so the download is performed again.

Is there a way to download the image once and save it at different resolutions so I can show the same image at two resolutions with a single download?

e.g. download an image at 1000x1000 then save it at 1000x1000 and at 100x100. That way I can smoothly show a list of 100x100 images but also view a full 1000x1000 image on its own.

Would it be sensible to add a List<Size> cacheSizes; property to OptimizedCacheImage?

Thanks!

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!

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

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.

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)

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

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!

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.