-1

I tried to load an image from gallery the code throw an Exception . The Exception is :Unhandled Exception: type 'PickedFile' is not a subtype of type 'File' in type cast This is my code:

_imgFromGallery() async {
PickedFile image = await ImagePicker().getImage(source: ImageSource.gallery);
if (image == null)
  return null;
setState(() {
  _isloading = false;
  _image = image as File;
});
classify(image as File);

}

1 Answers1

0

Your error is because you're trying to cast a PickedFile into a File. You can give the path property of your PickedFile to a File constructor instead.

...
setState(() {
  _isloading = false;
  _image = File(image.path)
});
classify(File(image.path));
...
BLKKKBVSIK
  • 3,128
  • 2
  • 13
  • 33