Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - display local image from Camera

Tags:

flutter

dart

I have generated an image using the Flutter camera plugin. I am trying to display it.

My path looks like:

/data/user/0/com.example.myapp/app_flutter/picture2.jpg

How should I load it ?

I tried :

new Image.network("file:///"+imagePath)

but I get the error :

Another exception was thrown: Invalid argument(s): No host specified in URI file:////data/user/0/com.example.myapp/app_flutter/picture2.jpg
like image 529
gpasse Avatar asked May 16 '18 18:05

gpasse


People also ask

How do I select an image from camera Flutter?

Flutter comes with an image picker plugin for picking images from the device gallery or taking new pictures from the camera. The image_picker plugin exposes some helpful methods from the ImagePicker class it exports: import 'package:image_picker/image_picker. dart'; ImagePicker picker = ImagePicker();


2 Answers

The way is to use :

new Image.file(File(imagePath))

see stackoverflow questions

like image 69
gpasse Avatar answered Nov 02 '22 23:11

gpasse


Use FileImage like below. It takes the File as the parameter.

 _image = File(path);

Container(
               padding: const EdgeInsets.all(1.0),
               decoration: BoxDecoration(
               color: Colors.white,
               image: DecorationImage(
                          image: FileImage(_image), fit: BoxFit.cover)),
              )
like image 43
Amir Avatar answered Nov 03 '22 00:11

Amir