Reputation: 983
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.
Upvotes: 33
Views: 90583
Reputation: 1
For those who have tried Image.file(File(path)) and have an issue with argument. The issue is because of imported dart:HTML. Try to import 'dart:io'. Then it will work fine
Upvotes: -1
Reputation: 4397
Suggested solutions do not work. Working solution in 2022:
import 'dart:io';
Container(child:
Image.file(File(savedImage!.path))),
Upvotes: 5
Reputation: 129
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.
Upvotes: 12
Reputation: 657308
The Image
class has a file
constructor for that
https://api.flutter.dev/flutter/widgets/Image/Image.file.html
Image.file(File(path))
Upvotes: 65
Reputation: 43
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
Upvotes: 3
Reputation: 81
I had the same problem, and I solved it with the following code:
Image.file(new File(StringPathVariable)
Upvotes: 7