openPickImage method
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,
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;
}