changeImage function

Future<File?> changeImage(
  1. BuildContext context,
  2. Widget modal,
  3. bool shouldCrop,
  4. CroppedImageOptions? croppedImageOptions,
  5. ImagePickerOptions? imagePickerOptions,
)

Alters the actual image

Implementation

Future<File?> changeImage(BuildContext context, Widget modal, bool shouldCrop,
  CroppedImageOptions? croppedImageOptions,
ImagePickerOptions? imagePickerOptions) async {
  final ImagePicker _picker = ImagePicker();
  File? response;
  ImageSource? type;
  if (kIsWeb) {
    type = ImageSource.gallery;
  } else {
    type = await showModalBottomSheet<ImageSource?>(
      context: context, builder: (context) => modal);
  }
  if (type != null) {
    imagePickerOptions ??= ImagePickerOptions();

    final XFile? _picked = await _picker.pickImage(source: type,
      imageQuality: imagePickerOptions.imageQuality,
      maxHeight: imagePickerOptions.maxHeight,
      maxWidth: imagePickerOptions.maxWidth,
      preferredCameraDevice: imagePickerOptions.preferredCameraDevice
    );
    if (_picked != null) {
      if (shouldCrop) {
        response = await cropImage(_picked, croppedImageOptions);
      }
      else {
        response = File(_picked.path);
      }
    }
  }
  return response;
}