pickImage function
Future<void>
pickImage(
- GetImageSource? getImageSource,
- GetPreferredCameraDevice? getPreferredCameraDevice,
- OnImageChanged? onImageChanged
Implementation
Future<void> pickImage(
GetImageSource? getImageSource,
GetPreferredCameraDevice? getPreferredCameraDevice,
OnImageChanged? onImageChanged) async {
final ImagePicker picker = ImagePicker();
ImageSource? source = ImageSource.gallery;
if (getImageSource != null) {
source = await getImageSource();
if (source == null) return;
}
CameraDevice? preferredCameraDevice = CameraDevice.rear;
if (source == ImageSource.camera) {
preferredCameraDevice = await getPreferredCameraDevice?.call();
if (preferredCameraDevice == null) {
return;
}
}
await picker
.pickImage(
source: source,
preferredCameraDevice: preferredCameraDevice,
)
.then<void>(
(XFile? value) {
if (value == null) return;
onImageChanged?.call(value);
},
);
}