Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter open images from file path

Tags:

flutter

dart

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.

like image 887
Niccolo Avatar asked Sep 29 '18 14:09

Niccolo


People also ask

How do I show image preview in Flutter?

First of all, you need to add camera plugin to your project by adding the following lines in pubspec. yaml file. Now, you can display the preview from Camera inside your app using CameraPreview() widget: CameraPreview(controller!)

What is AssetImage in Flutter?

A flutter app when built has both assets (resources) and code. Assets are available and deployed during runtime. The asset is a file that can include static data, configuration files, icons, and images. The Flutter app supports many image formats, such as JPEG, WebP, PNG, GIF, animated WebP/GIF, BMP, and WBMP.

How to load image from a local file in flutter?

This tutorial shows you how to load image from a local file in Flutter using Image.File and FileImage. Sometimes an application needs to be able to display images from files. In Flutter, displaying an image can be done by using Image widget. Flutter provides a named constructor File.Image which can be used if the image source is from a file.

How to mix assets and images in flutter?

Either you use assets, then you can use Image.asset () or you use a file with Image.file (). The way you mix it can't work. For assets see flutter.io/docs/development/ui/assets-and-images Asset and file is not the same.

What is flutteragency?

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget Guide , Flutter Projects , Code libs and etc.

How to handle storage permission in flutter pub get?

After running flutter pub get (or click on 'Packages get' in Android Studio), the package can be used by adding this import statement. Below is a code sample to handle storage permission. Below is the named constructeor Image.File. The basic usage only requires you to pass an argument which is an instance of File.


2 Answers

The Image class has a file constructor for that

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

Image.file(File(path))
like image 77
Günter Zöchbauer Avatar answered Oct 22 '22 10:10

Günter Zöchbauer


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

like image 25
Imanol Martinez Avatar answered Oct 22 '22 12:10

Imanol Martinez