Here is my code. Instead of passing jus 50 in image quality paramater. I wanted to set the image I am getting from this image picker library not to greater than 2 mb.
try {
var image = await ImagePicker.platform
.pickImage(source: imageSource, imageQuality: 50);
if (image != null) {
onImagePicked(image);
Navigator.pop(context);
}
} catch (e) {
return null;
}