Flutter ImagePicker 库不调用异步等待函数?

Flutter ImagePicker library not invoking aysnc await function?

我对 ImagePicker 库和 async-await 函数有疑问。所以在我的主页视图中,我调用了一个函数,代码如下

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

所以我尝试调试这个打印,所以我得到了第一个打印但之后什么都没有,看起来我失去了等待部分,我不知道到底是什么问题,它看起来等待部分永远不会执行。

这样试试。

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