openPickImage method

  1. @override
Future<String?> openPickImage(
  1. DeviceMediaSource source, {
  2. bool needCrop = false,
  3. CropType cropType = CropType.circle,
  4. bool isCameraFront = false,
  5. bool needCompress = false,
})
override

Implementation

@override
Future<String?> openPickImage(
  DeviceMediaSource source, {
  bool needCrop = false,
  CropType cropType = CropType.circle,
  bool isCameraFront = false,
  bool needCompress = false,
}) 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);

  return pathCrop;
}