Skip to content

Commit

Permalink
Merge pull request #47 from koji-1009/feat/on_memory_resize
Browse files Browse the repository at this point in the history
feat: Add on memory resize mode
  • Loading branch information
koji-1009 authored Jul 31, 2024
2 parents 88e5802 + 3c0bed0 commit a77a9b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
15 changes: 13 additions & 2 deletions lib/src/taro.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:typed_data';

import 'package:flutter/painting.dart';
import 'package:taro/src/taro_image.dart';
import 'package:taro/src/taro_loader.dart';
import 'package:taro/src/taro_loader_network.dart';
Expand Down Expand Up @@ -78,20 +79,30 @@ class Taro {
/// If [checkMaxAgeIfExist] is true, the method checks the max age of the data.
/// [ifThrowMaxAgeHeaderError] is used to throw an exception if the max age header is invalid.
/// The [resizeOption] parameter is used to resize the image. If it is not provided, the default resize option is used.
TaroImage loadImageProvider(
ImageProvider loadImageProvider(
String url, {
double scale = 1.0,
Map<String, String> headers = const {},
TaroResizeOption? resizeOption,
TaroHeaderOption? headerOption,
}) {
return TaroImage(
final image = TaroImage(
url,
scale: scale,
resizeOption: resizeOption ?? _resizeOption,
headers: headers,
headerOption: headerOption ?? _headerOption,
);

if (resizeOption?.mode == TaroResizeMode.memory) {
return ResizeImage.resizeIfNeeded(
resizeOption?.maxWidth,
resizeOption?.maxHeight,
image,
);
}

return image;
}

/// Loads the data from the provided URL and returns it as a byte array.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/taro_resizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TaroResizer {
required String contentType,
required TaroResizeOption resizeOption,
}) async {
if (resizeOption.mode == TaroResizeMode.skip) {
if (resizeOption.mode case TaroResizeMode.skip || TaroResizeMode.memory) {
// do nothing
return (
bytes: bytes,
Expand Down
17 changes: 10 additions & 7 deletions lib/src/taro_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,28 @@ enum TaroResizeMode {
/// The image is not resized.
skip,

/// The image is resized to the original contentType.
/// The image is resized and saved original image.
memory,

/// The image is resized to the original contentType and saved cache.
original,

/// The image is resized to a gif.
/// The image is resized to a gif and saved cache.
gif,

/// The image is resized to a jpg.
/// The image is resized to a jpg and saved cache.
jpeg,

/// The image is resized to a png.
/// The image is resized to a png and saved cache.
png,

/// The image is resized to a bmp.
/// The image is resized to a bmp and saved cache.
bmp,

/// The image is resized to a ico.
/// The image is resized to a ico and saved cache.
ico,

/// The image is resized to a tiff.
/// The image is resized to a tiff and saved cache.
tiff,
}

Expand Down

0 comments on commit a77a9b9

Please sign in to comment.