diff --git a/lib/platform_image_converter.dart b/lib/platform_image_converter.dart index 5a46bf8..e607f88 100644 --- a/lib/platform_image_converter.dart +++ b/lib/platform_image_converter.dart @@ -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 _convertInIsolate( +FutureOr _convertInIsolate( ({ Uint8List inputData, OutputFormat format, @@ -119,12 +119,9 @@ Future _convertInIsolate( TargetPlatform platform, }) request, -) { - final platform = _getPlatformForTarget(request.platform); - return platform.convert( - inputData: request.inputData, - format: request.format, - quality: request.quality, - resizeMode: request.resizeMode, - ); -} +) => _getPlatformForTarget(request.platform).convert( + inputData: request.inputData, + format: request.format, + quality: request.quality, + resizeMode: request.resizeMode, +); diff --git a/lib/src/android/native.dart b/lib/src/android/native.dart index 91a4d7a..d848066 100644 --- a/lib/src/android/native.dart +++ b/lib/src/android/native.dart @@ -34,12 +34,12 @@ final class ImageConverterAndroid implements ImageConverterPlatform { const ImageConverterAndroid(); @override - Future 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( diff --git a/lib/src/android/stub.dart b/lib/src/android/stub.dart index 907b412..3b8a3ca 100644 --- a/lib/src/android/stub.dart +++ b/lib/src/android/stub.dart @@ -7,10 +7,10 @@ final class ImageConverterAndroid implements ImageConverterPlatform { const ImageConverterAndroid(); @override - Future convert({ + Uint8List convert({ required Uint8List inputData, OutputFormat format = OutputFormat.jpeg, int quality = 100, ResizeMode resizeMode = const OriginalResizeMode(), - }) async => throw UnimplementedError(); + }) => throw UnimplementedError(); } diff --git a/lib/src/darwin/native.dart b/lib/src/darwin/native.dart index aad1322..8479175 100644 --- a/lib/src/darwin/native.dart +++ b/lib/src/darwin/native.dart @@ -37,12 +37,12 @@ final class ImageConverterDarwin implements ImageConverterPlatform { const ImageConverterDarwin(); @override - Future convert({ + Uint8List convert({ required Uint8List inputData, OutputFormat format = OutputFormat.jpeg, int quality = 100, ResizeMode resizeMode = const OriginalResizeMode(), - }) async { + }) { Pointer? inputPtr; CFDataRef? cfData; CGImageSourceRef? imageSource; diff --git a/lib/src/darwin/stub.dart b/lib/src/darwin/stub.dart index bf3c39c..0f109f8 100644 --- a/lib/src/darwin/stub.dart +++ b/lib/src/darwin/stub.dart @@ -8,10 +8,10 @@ final class ImageConverterDarwin implements ImageConverterPlatform { const ImageConverterDarwin(); @override - Future convert({ + Uint8List convert({ required Uint8List inputData, OutputFormat format = OutputFormat.jpeg, int quality = 100, ResizeMode resizeMode = const OriginalResizeMode(), - }) async => throw UnimplementedError(); + }) => throw UnimplementedError(); } diff --git a/lib/src/image_converter_platform_interface.dart b/lib/src/image_converter_platform_interface.dart index ab9756c..ae70a56 100644 --- a/lib/src/image_converter_platform_interface.dart +++ b/lib/src/image_converter_platform_interface.dart @@ -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 convert({ + FutureOr convert({ required Uint8List inputData, OutputFormat format = OutputFormat.jpeg, int quality = 100, diff --git a/lib/src/web/stub.dart b/lib/src/web/stub.dart index 84a5f99..e12858a 100644 --- a/lib/src/web/stub.dart +++ b/lib/src/web/stub.dart @@ -8,10 +8,10 @@ final class ImageConverterWeb implements ImageConverterPlatform { const ImageConverterWeb(); @override - Future convert({ + Uint8List convert({ required Uint8List inputData, OutputFormat format = OutputFormat.jpeg, int quality = 100, ResizeMode resizeMode = const OriginalResizeMode(), - }) async => throw UnimplementedError(); + }) => throw UnimplementedError(); }