mreig
mreig

Reputation: 177

Flutter - Load path from gallery image

How can I load a image from gallery by Flutter?

For example, I have:

 final logo = Image.asset(
    '//storage/emulated/0/DCIM/Camera/IMG_20181122_181848.jpg',
    fit: BoxFit.contain,
    height: 230.0,
  );

This does not work. I understand that this will only work in Android. I prefer a good option for Android and iOS, but I don't know how.

Can you help me? Thanks.

Upvotes: 0

Views: 6451

Answers (3)

Mohamed Hesham
Mohamed Hesham

Reputation: 1

You can load an image with image picker package https://pub.dev/packages/file_picker.

First you should choose your image by writing:

FilePickerResult result = await FilePicker.platform.pickFiles(); 
if (result != null) 
   File image = File(result.files.single.path);

Second you should view your image:

Image.file(image);

Upvotes: 0

mreig
mreig

Reputation: 177

Solved:

var file = new File('/storage/emulated/0/DCIM/Camera/IMG_20181122_181848.jpg');
return Image.file(file);

So: It is important to use Image.file and the absolute path has 1 "/" in the first position not 2.

:)

Upvotes: 3

Chris Reynolds
Chris Reynolds

Reputation: 5503

If I understand you correctly, There is an image_picker module that should do what you want.

Upvotes: 2

Related Questions