Baseflow / Baseflow/flutter_cached_network_image

Cache image in several different dimensions with one download

Open
#622 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
2.6k
Forks
731
Avg merge
3d 9h
Merged PRs (30d)
1

Description

## 🚀 Feature Requests

I would like to have a method to download source image once and resize it several with several different dimensions, then store the resized ones in the cache together. This feature would be useful if I want to provide users with different sizes of avatars throughout my app.

### Contextualize the feature
This feature requires little modification to current code (mostly down to the `flutter_cache_manager).

It should either:
1. Expose a new API function to download, resize and cache images, without building a widget
2. Provide extra optional keyword parameters in both `CachedNetowrkImage` and `CachedNetworkImageProvider` to allow batch resizing & caching

In `flutter_cache_maanger`, enhancement for `ImageCacheManager` would also be required. This would either:
1. Refactor the code and expose new API for batch resizing
2. Via an optional keyword parameter.

During some initial tryouts of coding PR for this, I think it would be better to discuss with you the best approach, as none of them seems ideal to me now. One concern is that Flutter does not have a built-in `Pair` or `Tuple`, and `Size` does not constrain itself to integers, which makes it ugly to pass a list of `int` pairs —— I have to choose from:
1. Introduce `dartz` (too heavy)
2. Write own int-pair class
3. Use 2 `Iterable`, yet the length may not match
4. Use `MapEntry`, yet the semantic meaning does not match
5. Use `Size`, yet the type does not check, and this is prune to rounding errors

### Describe the feature
Suppose we have a extra int-pair class named `IntSize`, we could have

```Dart
CachedNetworkImage(
imageUrl: "https://avatars.githubusercontent.com/u/12524680?v=4",
width: 100,
height: 100,
memCacheWidth: 100,
memCacheHeight: 100,
maxDiskCacheSizes: [
IntSize(100, null),
IntSize(null, 50),
IntSize(25, 25),
],
);
```

Or

```Dart
PrecacheImages(
imageUrl: "https://avatars.githubusercontent.com/u/12524680?v=4",
maxDiskCacheSizes: [
IntSize(100, null),
IntSize(null, 50),
IntSize(25, 25),
],
);
```

### Platforms affected (mark all that apply)
- [x] :iphone: iOS
- [x] :robot: Android

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.