flutter imagePicker库不调用Aysnc等待功能?
我对ImagePicker库和异步 - WAIT函数有问题。因此,从我的家庭视图中,我调用了一个函数,这是
onPressed: () {
controller.pickImage();
},
我使用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));
}
}
,所以我试图通过此打印进行调试,所以我得到了第一个打印一部分,我不知道实际上是什么问题,看起来等待部分从未执行过。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样。
Try like this.