Skip to content
This repository has been archived by the owner on Jun 25, 2023. It is now read-only.

Support new flutter_cache_manager 2.x #30

Closed
winterdl opened this issue Dec 9, 2020 · 16 comments
Closed

Support new flutter_cache_manager 2.x #30

winterdl opened this issue Dec 9, 2020 · 16 comments
Labels

Comments

@winterdl
Copy link

winterdl commented Dec 9, 2020

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

@humblerookie
Copy link
Owner

Thanks for reporting this,
I'll take a look and upgrade it.

@amugofjava
Copy link

I've found the same thing. optimized_cached_image has really helped with reducing crashes in my app due to lots of images, but it would be fantastic if its dependencies could be updated.

@humblerookie
Copy link
Owner

humblerookie commented Feb 22, 2021

@amugofjava I have been trying to upgrade sometime back but deferred since a lot of the code for the fcm has changed.
It seems like the original purpose of this library has been implemented via this PR. This includes pretty much most of the functionality OIC was built for. I'd recommend migrating to it.
The only thing missing is probably automatically detecting layout size which should be straightforward i.e. adding a layoutbuilder and supplying maxHeightDiskCache/maxWidthDiskCache for the CachedNetworkImage instance.

I'll publish a migration guide soon after comparing memory footprint, since the cache manager library uses image library (known to have performance issues on android and ios) to compress whereas OIC uses flutter_image_compress.

@humblerookie
Copy link
Owner

I was checking this today and it seems the benchmarks are still way off, almost like 9x difference in memory footprint, I feel this might be due to the use of image library in flutter_cache_manager which is inefficient. I'll update this library for compatibility now.

@amugofjava
Copy link

amugofjava commented Feb 28, 2021

Thanks @humblerookie,

I did take a good look at the new Image support in the cache manager, but you're right here, their choice of image library is not as efficient. What I like about your package is that it's fast and more memory efficient than other packages I have tried.

@winterdl
Copy link
Author

winterdl commented Mar 6, 2021

The flutter_cached_network_image always make my app crashes, maybe the fcm ver 2 uses a lot of memory as you mentioned.

@humblerookie
Copy link
Owner

humblerookie commented Mar 8, 2021

@winterdl @amugofjava I've updated this library to the new FCM, Here's the pre-release 2.0.0-dev.1. If you wish to try it out.

Also the relevant PR

@amugofjava
Copy link

Thanks @humblerookie - that's fantastic. Will give the pre-release a try and let you know how it goes.

@winterdl
Copy link
Author

winterdl commented Mar 9, 2021

Thanks @humblerookie, I will try the update and let you know.

I've just updated new version, this is the error logs:

EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE
╞════════════════════════════════════════════════════
The following _TypeError was thrown resolving an image codec:
type '_File' is not a subtype of type 'File'

When the exception was thrown, this was the stack:
#0      DefaultImageTransformer._scaleImageFile
(package:optimized_cached_image/src/transformer/image_transformer.dart:67:9)
<asynchronous suspension>
#1      DefaultImageTransformer.transform
(package:optimized_cached_image/src/transformer/image_transformer.dart:33:19)
<asynchronous suspension>
#2      OicImageCacheManager._resizeImageFile
(package:optimized_cached_image/src/cache/image_cache_manager.dart:85:9)
<asynchronous suspension>
#3      OicImageCacheManager._fetchedResizedFile
(package:optimized_cached_image/src/cache/image_cache_manager.dart:124:15)
<asynchronous suspension>
[✓] Flutter (Channel stable, 2.0.1, on macOS 11.2.3 20D91 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.54.1)
[✓] Connected device (3 available)

@yenyichau
Copy link

Thanks @humblerookie, I will try the update and let you know.

I've just update new version, this is the errors log:

EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE
╞════════════════════════════════════════════════════
The following _TypeError was thrown resolving an image codec:
type '_File' is not a subtype of type 'File'

When the exception was thrown, this was the stack:
#0      DefaultImageTransformer._scaleImageFile
(package:optimized_cached_image/src/transformer/image_transformer.dart:67:9)
<asynchronous suspension>
#1      DefaultImageTransformer.transform
(package:optimized_cached_image/src/transformer/image_transformer.dart:33:19)
<asynchronous suspension>
#2      OicImageCacheManager._resizeImageFile
(package:optimized_cached_image/src/cache/image_cache_manager.dart:85:9)
<asynchronous suspension>
#3      OicImageCacheManager._fetchedResizedFile
(package:optimized_cached_image/src/cache/image_cache_manager.dart:124:15)
<asynchronous suspension>
[✓] Flutter (Channel stable, 2.0.1, on macOS 11.2.3 20D91 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.54.1)
[✓] Connected device (3 available)

I got this errors too. Any idea ?

@amugofjava
Copy link

Hi @humblerookie,

I am getting the same error with _File. I think it might be an issue with the file package that flutter_cache_manager uses. The factory method in io.File returns a _File instance unless another API plugs in and overwrites some or all of the methods:

  factory File(String path) {
    final IOOverrides? overrides = IOOverrides.current;
    if (overrides == null) {
      return new _File(path);
    }
    return overrides.createFile(path);
  }

The file packages provides implementation for the io.File methods such as createFile. It may be that either via a bug or some missing setup perhaps that the file package is not setting up the overrides.

The result is that in image_transformer.dart at the end of _scaleImage a new fileInfo is created. It expects a File object but gets a _File instead from the default io.File factory method.

@humblerookie
Copy link
Owner

@amugofjava @yenyichau Thanks for your feedback, I'll take a look

@humblerookie
Copy link
Owner

humblerookie commented Mar 19, 2021

I am getting the same error with _File. I think it might be an issue with the file package that flutter_cache_manager uses. The factory method in io.File returns a _File instance unless ano

@amugofjava, @winterdl Essentially the flutter_cache_manager uses the file package which has a conflicting name with the dart:io package File. Its silly but dart is shitty when it comes to compile-time safety checks.

This issue is fixed via #36 . I've released a new version on pub
2.0.0-dev.2. Do give it a shot and let me know if the issue still persists for you.

@humblerookie
Copy link
Owner

Closing this issue feel free to reopen, in case there is any issue

@winterdl
Copy link
Author

Thank you, it works, but I have to add dependency overrides for some package:
Warning: You are using these overridden dependencies:
archive, crypto, ! http_parser 4.0.0, ! path_provider 2.0.1

@amugofjava
Copy link

Works for me @humblerookie, but I did need to check it out from source in order to update flutter_cache_manager in pubspec.yaml to the null safe one - which then worked fine :)

flutter_cache_manager: ^3.0.0-nullsafety.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants