getImageFromSource method

  1. @override
Future<XFile?> getImageFromSource({
  1. required ImageSource source,
  2. ImagePickerOptions options = const ImagePickerOptions(),
})
override

Returns an XFile with the image that was picked.

The source argument controls where the image comes from. This can be either ImageSource.camera or ImageSource.gallery.

The options argument controls additional settings that can be used when picking an image. See ImagePickerOptions for more details.

Where iOS supports HEIC images, Android 8 and below doesn't. Android 9 and above only support HEIC images if used in addition to a size modification, of which the usage is explained in ImagePickerOptions.

In Android, the MainActivity can be destroyed for various reasons. If that happens, the result will be lost in this call. You can then call getLostData when your app relaunches to retrieve the lost data.

If no images were picked, the return value is null.

Implementation

@override
Future<XFile?> getImageFromSource({
  required ImageSource source,
  ImagePickerOptions options = const ImagePickerOptions(),
}) async {
  if (source == ImageSource.camera) {
    final ImagePickerCameraDelegate? delegate = cameraDelegate;
    if (delegate == null) {
      throw StateError(
          'This implementation of ImagePickerPlatform requires a '
          '"cameraDelegate" in order to use ImageSource.camera');
    }
    return delegate.takePhoto(
        options: ImagePickerCameraDelegateOptions(
      preferredCameraDevice: options.preferredCameraDevice,
    ));
  }
  return super.getImageFromSource(source: source, options: options);
}