Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Save set image of PickedFile type to a image in Flutter?

Tags:

flutter

dart

I want to set get image from the camera and set it to the following code:

image: DecorationImage(image: FileImage(file),

So I did this:

File file = await ImagePicker.pickImage(
  source: ImageSource.camera,
);

Now above code works fine for now, but 'pickImage' is deprecated and we should use imagePicker.getImage() method instead.

So I used imagePicker.getImage() instead:

PickedFile file = await ImagePicker().getImage(
  source: ImageSource.camera,
);

But when I try to set this file to the following image type, it doesn't work

image: DecorationImage(image: FileImage(file),)

How to solve this issue?

like image 208
Aakash Solanki Avatar asked Jun 01 '20 09:06

Aakash Solanki


People also ask

How do I convert a widget to an image flutter?

Image image = await boundary. toImage(pixelRatio: 3.0); After getting raw image data we convert it to bytecode and after that, we convert the bytecode to Unit8List which we can use to get a base64 string. That's all for today.


2 Answers

You need to use path property of picked file

image: DecorationImage(image: FileImage(File(file.path)),)
like image 78
Rahul Sharma Avatar answered Oct 03 '22 14:10

Rahul Sharma


If someone might struck on a similar issue

change from pickImage to getImage and still needs a File.

PickedFile selectedFile = await ImagePicker().getImage(source: source);
File selected = File(selectedFile.path);
like image 22
Bliv_Dev Avatar answered Oct 03 '22 16:10

Bliv_Dev