flutter - 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>'.
我了解错误,无法将文件分配给小部件,但是我不知道如何解决它?
解决方案
问题似乎就在这里List<Widget> image = _images
。
尝试
List<Widget> imageWidgets = _images.map<Image>((c) => new Image.file(c)).toList();
推荐阅读
- model - Asp.net mvc4 对象引用未设置为对象的实例
- typescript - 如何将打字稿定义拆分为多个文件?
- android - BLE,使用服务 A 或 B 或 C 扫描设备
- java - 为什么我的 Java9 模块服务不工作?
- filter - 在 mapbox gl js 中使用多个过滤器的数据驱动样式
- collections - 如何在 Blueprism 中将集合设置为空
- swagger - 用于值验证的远程枚举列表 - 在 OpenAPI 规范中
- node.js - HTTP 发送后请求失败
- python - 用python从json中提取数据
- php - 是否有可能从这段代码中形成某种循环?