flutter - 元素类型'Iterable'不能分配给列表类型'Widget'颤动
问题描述
在 Flutter Row of List 中渲染图像列表时出现此错误
import 'package:flutter/material.dart';
import '../../helper/mapIndexed.dart';
const List imageList = [
'https://res.cloudinary.com/du8msdgbj/image/upload/w_560,h_240,,a_ignore,q_auto,f_auto/v1609697109/e42avkuozkqhh8u3dh70.png',
'https://res.cloudinary.com/du8msdgbj/image/upload/w_560,h_240,,a_ignore,q_auto,f_auto/v1609697073/ncuy4b9rnhrwjdwkp6dy.png',
'https://res.cloudinary.com/du8msdgbj/image/upload/w_560,h_240,,a_ignore,q_auto,f_auto/v1609697374/wf6qw4izw2mi1okmex39.png'
];
class SilpleCarousel extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
children: [
// here is the issue
imageList.mapIndexed((e, i) => Container())
],
);
}
}
解决方案
如果我们在 List 上使用 spreed 运算符...
,我们可以克服这个
return Row(
children: [
// here we can spreed ...
...imageList.mapIndexed((e, i) => Container())
],
);
推荐阅读
- c# - Blazor 服务器端项目中的内存泄漏
- ios - 为什么我必须使用 print((sender as AnyObject).currentTitle!!) 来打印标题而 print(sender.currentTitle) 不起作用?
- machine-learning - 使用 PCA 解决回归问题时降低模型精度
- python - 展平python中的列表列表并创建不同的数据框
- python - Pandas:将特定列值拆分为新列,并在所有新创建的列中查找值的出现
- java - 使用 Java 反射访问嵌套字段
- javascript - 如何在我的 HTML 表格中添加排序符号?
- javascript - React 状态钩子,togle 类,为什么两个元素都获得“活动”类?
- database - 可能有多少不同的最小覆盖?
- detox - Detox by.id 不是函数