I have an issue with the ImagePicker library and async-await function. So on my home view, I invoke a function, here is the code
onPressed: () {
controller.pickImage();
},
Here is my function with ImagePicker
void pickImage() async {
print("call on click add photo icon");
final ImagePicker _picker = ImagePicker();
final XFile? pickedImage =
await _picker.pickImage(source: ImageSource.gallery);
print(
'picked image filled with an image from gallery'); //This doesn't print at all
if (pickedImage != null) {
Get.snackbar('Profile Picture',
'You have successfully selected your profile picture!');
_pickedImage = Rx<File>(File(pickedImage.path));
}
}
So I tried to debug with this printing, so I get the first print but after that nothing, it looks like I'm losing that await part, I don't know what actually is the problem, it looks await part is never executed.
CodePudding user response:
Try like this.
Future pickImage() async {
print("call on click add photo icon");
ImagePicker _picker = ImagePicker();
XFile pickedImage =
await _picker.pickImage(source: ImageSource.gallery);
print(
'picked image filled with an image from gallery'); //This doesn't print at all
if (pickedImage != null) {
Get.snackbar('Profile Picture',
'You have successfully selected your profile picture!');
_pickedImage = File(pickedImage.path);
}}