如何修复 ImagePicker 取消按钮上的“NoSuchMethodError:getter 'path' was called on null”?

时间:2021-01-12 14:42:13

标签: flutter

伙计们,我正在使用 ImagePicker 插件访问我的应用程序中的图像,但是如果我决定取消它,我会收到此错误 NoSuchMethodError: The getter 'path' was called on null。关于如何修复它的任何想法?

这是我的ImagePicker

FlatButton(
          onPressed: () async {
            final PickedFile file =
                await picker.getImage(source: ImageSource.camera);
            editImage(file.path);
          },
          child: Text('Câmera'),
        ), 

1 个答案:

答案 0 :(得分:0)

修复:

FlatButton(
          onPressed: () async {
            final PickedFile file =
                await picker.getImage(source: ImageSource.camera);
            if (file != null) {
              editImage(file.path);
            }
          },
          child: Text('Câmera'),
        ),