flutter imagePicker库不调用Aysnc等待功能?

发布于 2025-01-22 05:25:36 字数 922 浏览 0 评论 0原文

我对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.

output of my code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你搞怪i 2025-01-29 05:25:36

尝试这样。

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);
}}

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);
}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文