normalize method
Normalizes the current file for upload or preview by returning a local File instance.
- If the file is in HEIC format (
isHeic == true), it is first converted to JPEG and copied to the app’s temporary directory using copyToTempWithResourceId. - Otherwise, the original file path is returned as a File instance.
This method is useful to ensure the file is in a supported and consistent format (e.g. avoiding HEIC incompatibilities on non-Apple platforms) before further processing.
If any error occurs during normalization (e.g. file not found or conversion failure),
it returns null gracefully.
Example:
final file = await myFile.normalize('res_456');
if (file != null) {
upload(file);
} else {
print('Normalization failed.');
}
Implementation
Future<File> normalize(String resourceId) async {
if (isHeic) {
final tempFile = await copyToTempWithResourceId(resourceId);
return File(tempFile.path);
} else {
return File(path);
}
}