feat: Update convert method to return FutureOr

This commit is contained in:
Koji Wakamiya 2025-12-29 07:58:56 +09:00
parent d7ffa28265
commit 43dafb8c01
No known key found for this signature in database
7 changed files with 20 additions and 22 deletions

View File

@ -85,7 +85,7 @@ class ImageConverter {
));
} else {
// The original implementation for those who opt-out.
return _platform.convert(
return await _platform.convert(
inputData: inputData,
format: format,
quality: quality,
@ -110,7 +110,7 @@ ImageConverterPlatform _getPlatformForTarget(TargetPlatform platform) {
}
/// Top-level function for `compute`.
Future<Uint8List> _convertInIsolate(
FutureOr<Uint8List> _convertInIsolate(
({
Uint8List inputData,
OutputFormat format,
@ -119,12 +119,9 @@ Future<Uint8List> _convertInIsolate(
TargetPlatform platform,
})
request,
) {
final platform = _getPlatformForTarget(request.platform);
return platform.convert(
) => _getPlatformForTarget(request.platform).convert(
inputData: request.inputData,
format: request.format,
quality: request.quality,
resizeMode: request.resizeMode,
);
}

View File

@ -34,12 +34,12 @@ final class ImageConverterAndroid implements ImageConverterPlatform {
const ImageConverterAndroid();
@override
Future<Uint8List> convert({
Uint8List convert({
required Uint8List inputData,
OutputFormat format = OutputFormat.jpeg,
int quality = 100,
ResizeMode resizeMode = const OriginalResizeMode(),
}) async {
}) {
return using((arena) {
final inputJBytes = JByteArray.from(inputData)..releasedBy(arena);
final originalBitmap = BitmapFactory.decodeByteArray(

View File

@ -7,10 +7,10 @@ final class ImageConverterAndroid implements ImageConverterPlatform {
const ImageConverterAndroid();
@override
Future<Uint8List> convert({
Uint8List convert({
required Uint8List inputData,
OutputFormat format = OutputFormat.jpeg,
int quality = 100,
ResizeMode resizeMode = const OriginalResizeMode(),
}) async => throw UnimplementedError();
}) => throw UnimplementedError();
}

View File

@ -37,12 +37,12 @@ final class ImageConverterDarwin implements ImageConverterPlatform {
const ImageConverterDarwin();
@override
Future<Uint8List> convert({
Uint8List convert({
required Uint8List inputData,
OutputFormat format = OutputFormat.jpeg,
int quality = 100,
ResizeMode resizeMode = const OriginalResizeMode(),
}) async {
}) {
Pointer<Uint8>? inputPtr;
CFDataRef? cfData;
CGImageSourceRef? imageSource;

View File

@ -8,10 +8,10 @@ final class ImageConverterDarwin implements ImageConverterPlatform {
const ImageConverterDarwin();
@override
Future<Uint8List> convert({
Uint8List convert({
required Uint8List inputData,
OutputFormat format = OutputFormat.jpeg,
int quality = 100,
ResizeMode resizeMode = const OriginalResizeMode(),
}) async => throw UnimplementedError();
}) => throw UnimplementedError();
}

View File

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:platform_image_converter/src/output_format.dart';
@ -31,7 +32,7 @@ abstract interface class ImageConverterPlatform {
/// - [ImageDecodingException]: If the input image data cannot be decoded.
/// - [ImageEncodingException]: If the image cannot be encoded to the target format.
/// - [ImageConversionException]: For other general errors during the conversion process.
Future<Uint8List> convert({
FutureOr<Uint8List> convert({
required Uint8List inputData,
OutputFormat format = OutputFormat.jpeg,
int quality = 100,

View File

@ -8,10 +8,10 @@ final class ImageConverterWeb implements ImageConverterPlatform {
const ImageConverterWeb();
@override
Future<Uint8List> convert({
Uint8List convert({
required Uint8List inputData,
OutputFormat format = OutputFormat.jpeg,
int quality = 100,
ResizeMode resizeMode = const OriginalResizeMode(),
}) async => throw UnimplementedError();
}) => throw UnimplementedError();
}