compressAndGetFile static method
From path
to targetPath
Implementation
static Future<File?> compressAndGetFile(
String path,
String targetPath, {
int minWidth = 1920,
int minHeight = 1080,
int inSampleSize = 1,
int quality = 95,
int rotate = 0,
bool autoCorrectionAngle = true,
CompressFormat format = CompressFormat.jpeg,
bool keepExif = false,
int numberOfRetries = 5,
}) async {
if (numberOfRetries <= 0) {
throw "numberOfRetries can't be null or less than 0";
}
if (!File(path).existsSync()) {
throw "Image file does not exist";
}
assert(
targetPath != path, "Target path and source path cannot be the same.");
_validator.checkFileNameAndFormat(targetPath, format);
final support = await _validator.checkSupportPlatform(format);
if (!support) {
return null;
}
final String? result =
await _channel.invokeMethod("compressWithFileAndGetFile", [
path,
minWidth,
minHeight,
quality,
targetPath,
rotate,
autoCorrectionAngle,
_convertTypeToInt(format),
keepExif,
inSampleSize,
numberOfRetries
]);
if (result == null) {
return null;
}
return File(result);
}