我正在学习flutter,我试着从fireship.io上重新创建它。
我复制了代码,得到了这个错误:
The element type 'Iterable<Widget>' can't be assigned to the list type 'Widget'.代码:
List items = [
MenuItem(x: -1.0, name: 'house'),
MenuItem(x: -0.5, name: 'planet'),
MenuItem(x: 0.0, name: 'camera'),
MenuItem(x: 0.5, name: 'heart'),
MenuItem(x: 1.0, name: 'head'),
];
Container(
// <-- 4. Main menu row
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.end,
children: [items.map((item) => _flare(item))],
),
),MenuItem类:
class MenuItem {
final String name; // name is the filename of the .flr asset
final double
x; // x is the X-axis alignment of the item (-1 is far left, 1 is far right).
MenuItem({required this.name, required this.x});我找到了一个具有相同错误的question,但我无法解决它。
发布于 2021-08-05 18:14:31
map返回iterable,所以你必须把它转换成list。你也不需要在那里使用[]。
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.end,
children: items.map((item) => _flare(item)).toList(),
),
),发布于 2021-08-05 18:14:04
试试这条路
children: [
...items.map((item) => _flare(item)).toList(),
],https://stackoverflow.com/questions/68671552
复制相似问题