0

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"),

1 Answer 1

1

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);}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.