pickImage static method
Future<String?>
pickImage({
- ImageSource source = ImageSource.gallery,
- required void onError(
- String e
Picks a single image from the specified ImageSource.
Returns the file path of the picked image or null
if no image is selected.
Calls onError
in case of an error.
Implementation
static Future<String?> pickImage({
ImageSource source = ImageSource.gallery,
required void Function(String e) onError,
}) async {
try {
final pickedFile = await _imagePicker.pickImage(
source: source == ImageSource.camera
? image_picker.ImageSource.camera
: image_picker.ImageSource.gallery,
);
if (pickedFile == null) return null;
final path = pickedFile.path;
return path;
} catch (e) {
onError(e.toString());
return null;
}
}