Home > Software engineering >  Image picker giving error showing flutter
Image picker giving error showing flutter

Time:04-10

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

CodePudding user response:

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