Flutter: Picking images as jpg/png instead of heic on iOS

Viewed 5598

How can I pick images directly as jpg or png on iOS? If this feature isn't available: How can I convert it very fast and don't have to wait a long time?

Edit: I want to prevent picking .heic because I have to send it to an server, which handles jpg and png and not .heic

3 Answers

i select images with filepicker https://pub.dev/packages/file_picker

FilePickerResult result;
try {
  result = await FilePicker.platform.pickFiles(
    type: FileType.custom,
    allowedExtensions: ['jpeg', 'jpg', 'heic', 'pdf'],
  );
} catch (e) {
  print('Exep: ****${e}***');
}

now you can check the extention of the file, use the package path.dart as p and package https://pub.dev/packages/heic_to_jpg to convert image to jpeg

 File file = File(result.files.first.path);
  String fileExtension = p.extension(file.path).replaceAll('.', '');
  if (fileExtension == 'heic') {
    print('convert to jpeg');
    String jpegPath = await HeicToJpg.convert(file.path);
    file = File(jpegPath);
    fileExtension = 'jpeg';
  }

do not forget do the same if you use imagePicker with source camera.

Related