applyTransforms method
Implementation
Future<File> applyTransforms(XFile file) async {
busy = true;
image_pack.Image? image;
// image is mirrored. this is a stop gap measure. should be a transform
if ((direction ?? "") == fromEnum(CameraLensDirection.front)) {
image = image_pack.decodeJpg(await file.readAsBytes());
image = image_pack.flipHorizontal(image!);
// encode back to jpg
var bytes = image_pack.encodeJpg(image);
var name =
basename(isNullOrEmpty(file.name) ? "${newId()}.jpg" : file.name);
var uri = UriData.fromBytes(bytes, mimeType: await Mime.type(name));
var url = uri.toString();
var type = await Mime.type(name);
var size = bytes.length;
// save the image
busy = false;
return File(uri, url, name, type, size);
}
// no transformation applied
else {
// set file - 'file:' required so image widget will decode as a file path.
var url = file.path.startsWith("blob:") ? file.path : "file:${file.path}";
var name =
basename(isNullOrEmpty(file.name) ? "${newId()}.jpg" : file.name);
var type = await Mime.type(name);
var size = await file.length();
// save the image
busy = false;
return File(file, url, name, type, size);
}
}