颤动 - 显示摄像头的本地图像

时间:2018-05-16 18:00:00

标签: dart flutter

我使用Flutter camera plugin生成了一张图片。 我想显示它。

我的路径如下:

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

我应该如何加载它?

我试过了:

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

但是我收到了错误:

Another exception was thrown: Invalid argument(s): No host specified in URI file:////data/user/0/com.example.myapp/app_flutter/picture2.jpg

3 个答案:

答案 0 :(得分:5)

方法是使用:

new Image.file(File(imagePath))

请参阅stackoverflow questions

答案 1 :(得分:1)

使用 FileImage 如下。它以文件为参数。

 _image = File(path);

Container(
               padding: const EdgeInsets.all(1.0),
               decoration: BoxDecoration(
               color: Colors.white,
               image: DecorationImage(
                          image: FileImage(_image), fit: BoxFit.cover)),
              )

答案 2 :(得分:0)

从资产加载时,我遇到此错误

课程::使用Image.asset代替Image.network

示例:

Image.asset( "assets/image.png")

代替

Image.network( "assets/image.png")