首页 > 解决方案 > Flutter:列表的价值不能分配给 List 类型的变量

问题描述

我正在尝试映射选定的图像,以便可以在构建中显示它们。

我有:

 // declared earlier
List<File> _images;

List<Widget> image = _images
      if (_images != null) {
      _images.map((c) => new Image.file(c)
      ).toList();

这给了我以下错误:

'List<File>' can't be assigned to a variable of type 'List<Widget>'.

我了解错误,无法将文件分配给小部件,但是我不知道如何解决它?

标签: flutter

解决方案


问题似乎就在这里List<Widget> image = _images

尝试

List<Widget> imageWidgets = _images.map<Image>((c) => new Image.file(c)).toList();

推荐阅读