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.
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!)
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.
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.
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.
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.
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.
The Image
class has a file
constructor for that
https://api.flutter.dev/flutter/widgets/Image/Image.file.html
Image.file(File(path))
I had the same problem, and I solved it with the following code:Image.file(new File(StringPathVariable)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With