Reputation: 37
I'm learing flutter and I tried to recreate this from fireship.io.
I copied the code and I get this Error:
The element type 'Iterable<Widget>' can't be assigned to the list type 'Widget'.
Code:
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))],
),
),
Class 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});
I found a question with the same error but I couldn't solve it.
Upvotes: 1
Views: 941
Reputation: 107131
map returns iterable, so you've to convert that to list. Also you don't need to use [] there.
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.end,
children: items.map((item) => _flare(item)).toList(),
),
),
Upvotes: 1
Reputation: 63604
try this way
children: [
...items.map((item) => _flare(item)).toList(),
],
Upvotes: 0