Merge pull request #24 from koji-1009/refactor/futureor
feat: Update convert method to return FutureOr
This commit is contained in:
commit
b63e14b46d
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue