applyTransforms method
Implementation
Future<FILE.File> applyTransforms(XFile file) async
{
busy = true;
IMAGE.Image? image;
// image is mirrored. this is a stop gap measure. should be a transform
if ((direction ?? "") == S.fromEnum(CameraLensDirection.front))
{
image = IMAGE.decodeJpg(await file.readAsBytes());
image = IMAGE.flipHorizontal(image!);
// encode back to jpg
var bytes = IMAGE.encodeJpg(image);
var name = basename(S.isNullOrEmpty(file.name) ? "${S.newId()}.jpg" : file.name);
var uri = UriData.fromBytes(bytes, mimeType: await S.mimetype(name));
var url = uri.toString();
var type = await S.mimetype(name);
var size = bytes.length;
// save the image
busy = false;
return FILE.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(S.isNullOrEmpty(file.name) ? "${S.newId()}.jpg" : file.name);
var type = await S.mimetype(name);
var size = await file.length();
// save the image
busy = false;
return FILE.File(file, url, name, type, size);
}
}