'flutter open images from file path

I am using image_picker to get some images from gallery, and I saved the path of the images in a list, like:

/private/var/mobile/Containers/Data/Application/E633FB78-77D3-4913-B37A-496BFBAAD00C/tmp/image_picker_EA6D2836-3EAD-438C-AEEE-21CB3500ED28-9410-00000706FA96031D.jpg

how can I open the image from the path in flutter?

I tried Image.file, but it doesn't work, please help.



Solution 1:[1]

The Image class has a file constructor for that

https://api.flutter.dev/flutter/widgets/Image/Image.file.html

Image.file(File(path))

Solution 2:[2]

I had the same problem, and I solved it with the following code:
Image.file(new File(StringPathVariable)

Solution 3:[3]

If I remember correctly Image.file() can only accept ImageProvider<Object>, and apparently File(imagePath) is categorized as Image type

So if Image.file(File(imagePath)) fail, you can add .image at the end to turn it into ImageProvider<Object>, so the following code should work:

Image.file(File(imageUri)).image

Solution 4:[4]

For those who have tried Image.file(File(path)) and have an issue with arguments, make sure you have imported dart:io, not dart:html, because sometimes it imports automatically.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 julemand101
Solution 2 Artemis
Solution 3 Chompions Sawelo
Solution 4