I am trying to understand the casting system of Dart, in specific with flutter.
I have a List of my custom type I would like to fill in a TableRow, but I simply fail to use map for it. Can anyone help me to point out what my problem is? At the end I need a list of widgets for the children parameter.
TableRow(
children: myList.map((MyType foo) {
return <Widget>[new Text(foo.name)];
}) as List<Widget>
),
The error I am getting is:
flutter: type 'MappedListIterable<MyType, List<Text>>' is not a subtype of type 'List<Widget>' in type cast
Any help is highly appreciated
Just do this:
TableRow(
children: myList.map((foo) {
return new Text(foo.name);
}).toList(),
),
As Rémi says, you need to return a widget inside the map() function, not a list of widgets. And then convert the iterable to a List with toList() method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With