pickImageFromGallery method
Future<File?>
pickImageFromGallery({
- double? maxWidth,
- double? maxHeight,
- int? imageQuality,
- bool enableCrop = false,
- CropSettings? cropSettings,
Implementation
Future<File?> pickImageFromGallery({
double? maxWidth,
double? maxHeight,
int? imageQuality,
bool enableCrop = false,
CropSettings? cropSettings,
}) async {
bool hasPermission = await _checkGalleryPermission();
if (!hasPermission) return null;
try {
final XFile? image = await _picker.pickImage(
source: ImageSource.gallery,
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: imageQuality,
);
if (image != null) {
File imageFile = File(image.path);
if (enableCrop) {
imageFile = await cropImage(imageFile, cropSettings: cropSettings) ??
imageFile;
}
return imageFile;
}
} catch (e) {
print('Error picking gallery image: $e');
}
return null;
}