首页 > 解决方案 > 颤振:image.file 未显示

问题描述

我用系统的照片0.2.0来获取照片,但是当我获取照片并刷新界面时,出现了空白。

代码:

PhotoPicker.pickAsset(
  context: context,
  // BuildContext required
  /// The following are optional parameters.
  themeColor: Colors.white,
  // the title color and bottom color
  padding: 4.0,
  //...
  //...
).then((List<AssetEntity> imgList) {
  //
  getPhotoFile(imgList);
});

获取文件到 List photoList

List<File> photoList = [];
getPhotoFile(List<AssetEntity> imgList) async {
  for (int i = 0; i < imgList.length; i++) {
    AssetEntity item = imgList[i];
    File tempFile = await item.file;
    photoList.add(tempFile);
  }
  setState(() {});
}

刷新用户界面

photoList.map<Widget>((File file) {
  return new FutureBuilder(
    future: _getLocalFile(file),
    builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
      return snapshot.data != null ? new Image.file(snapshot.data) : new Container();
        })
          : new Container();
    });
}.toList();

Future<File> _getLocalFile(File file) async {
  return file;
}

我得到 file.path 之类的

'/private/var/mobile/Containers/Data/Application/543EEE91-BD94-4EA7-969C-A4E3320C4B93/tmp/.images/3609017ffc0170a5968fc9edbb44eb9c.jpg'

我应该怎么做才能确保显示所有图片?

在此处输入图像描述

标签: dartflutterflutter-layout

解决方案


你能给出颤振医生 -v 的结果吗?
你能把你的形象包装起来吗?
用容器归档?
这是一个例子。

child: Container(
  decoration: BoxDecoration(color: Colors.teal),
  child: Padding(
    padding: const EdgeInsets.all(8.0),
    child: Image.file(

推荐阅读