refactor: Use typedef
This commit is contained in:
parent
b305c64a10
commit
708c486a09
|
|
@ -66,10 +66,12 @@ class ImageConverter {
|
||||||
bool runInIsolate = true,
|
bool runInIsolate = true,
|
||||||
}) async {
|
}) async {
|
||||||
if (runInIsolate) {
|
if (runInIsolate) {
|
||||||
return await compute(
|
return await compute(_convertInIsolate, (
|
||||||
_convertInIsolate,
|
inputData: inputData,
|
||||||
_ConvertRequest(inputData, format, quality, defaultTargetPlatform),
|
format: format,
|
||||||
);
|
quality: quality,
|
||||||
|
platform: defaultTargetPlatform,
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
// The original implementation for those who opt-out.
|
// The original implementation for those who opt-out.
|
||||||
return _platform.convert(
|
return _platform.convert(
|
||||||
|
|
@ -81,22 +83,6 @@ class ImageConverter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper class to pass arguments to the isolate.
|
|
||||||
@immutable
|
|
||||||
class _ConvertRequest {
|
|
||||||
final Uint8List inputData;
|
|
||||||
final OutputFormat format;
|
|
||||||
final int quality;
|
|
||||||
final TargetPlatform platform;
|
|
||||||
|
|
||||||
const _ConvertRequest(
|
|
||||||
this.inputData,
|
|
||||||
this.format,
|
|
||||||
this.quality,
|
|
||||||
this.platform,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the platform-specific converter instance.
|
/// Returns the platform-specific converter instance.
|
||||||
ImageConverterPlatform _getPlatformForTarget(TargetPlatform platform) {
|
ImageConverterPlatform _getPlatformForTarget(TargetPlatform platform) {
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
|
|
@ -112,7 +98,15 @@ ImageConverterPlatform _getPlatformForTarget(TargetPlatform platform) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Top-level function for `compute`.
|
/// Top-level function for `compute`.
|
||||||
Future<Uint8List> _convertInIsolate(_ConvertRequest request) {
|
Future<Uint8List> _convertInIsolate(
|
||||||
|
({
|
||||||
|
Uint8List inputData,
|
||||||
|
OutputFormat format,
|
||||||
|
int quality,
|
||||||
|
TargetPlatform platform,
|
||||||
|
})
|
||||||
|
request,
|
||||||
|
) {
|
||||||
final platform = _getPlatformForTarget(request.platform);
|
final platform = _getPlatformForTarget(request.platform);
|
||||||
return platform.convert(
|
return platform.convert(
|
||||||
inputData: request.inputData,
|
inputData: request.inputData,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue