Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Image picker giving error showing flutter

I was trying to upload the image to flutter app by using Image picker, all things were working fine but when I try to show the Image in the app it was giving the following error in code:
"The argument type ‘String’ can’t be assigned to the parameter type ‘File’"
this is the function I am calling:

 void takePhoto(ImageSource source) async {
Navigator.pop(context);
final PickedFile = await _picker.pickImage(source: source);
// final f = await PickedFile!.path;

setState(() {
  // ignore: unnecessary_cast
  _imageFile = PickedFile!;
  
});
print(_imageFile!.path);}

and when I print the path so it is giving me correct path but when I try to show the Image so it is giving the error, code for displaying image

 _imageFile!= null ? Image.file(
                      _imageFile!.path
                    ):
                    Text("no image"),

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try with this

void takePhoto(ImageSource source) async {
Navigator.pop(context);
final PickedFile = await _picker.pickImage(source: source);
// final f = await PickedFile!.path;

setState(() {
  // ignore: unnecessary_cast
  _imageFile = File(PickedFile!.path); // use with full path
  
});
print(_imageFile!.path);}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading