openPickImage method

  1. @override
Future<String?> openPickImage(
  1. DeviceMediaSource source, {
  2. bool needCrop = false,
  3. CropType? cropType = CropType.circle,
  4. double? ratioX,
  5. double? ratioY,
  6. bool isCameraFront = false,
  7. bool needCompress = false,
  8. int? maxWidth = 1000,
  9. int? maxHeight = 1200,
})
override

Implementation

@override
Future<String?> openPickImage(
  DeviceMediaSource source, {
  bool needCrop = false,
  CropType? cropType = CropType.circle,
  double? ratioX,
  double? ratioY,
  bool isCameraFront = false,
  bool needCompress = false,
  int? maxWidth = 1000,
  int? maxHeight = 1200,
}) async {
  // Pick an image
  final imgPath = await ImagePicker().pickImage(
    source: source.toImageSource(),
    preferredCameraDevice:
        isCameraFront ? CameraDevice.front : CameraDevice.rear,
  );

  if (imgPath == null) {
    return null;
  }

  final pathCompress =
      needCompress == false ? imgPath.path : await _compress(imgPath);

  if (pathCompress == null) {
    throw Exception('Cannot compress file');
  }

  final pathCrop = needCrop == false
      ? pathCompress
      : await _crop(
          pathCompress,
          cropType,
          maxWidth,
          maxHeight,
          ratioX,
          ratioY,
        );

  return pathCrop;
}