imagePicker function
- BuildContext context
A utility function that allows the user to pick an image from their gallery.
Implementation
Future<XFile?> imagePicker(BuildContext context) => ImagePicker()
.pickImage(source: ImageSource.gallery, maxWidth: 2000, maxHeight: 2000)
.then((image) {
if (image == null) {
return null;
}
// Check if the image is actually an image on web
if (kIsWeb && image.mimeType?.startsWith('image') != true) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(t.image.noImagePickedErrorMessage),
),
);
return null;
}
return image;
});