Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The element type 'Set<Text>' can't be assigned to the list type 'Widget' [duplicate]

Tags:

flutter

dart

With the following code, I am trying to add a new Text widget for each player:

Widget build(BuildContext context) {
    return Container(
        child: Row(children: [
          Column(
            children: [
              for (var player in _players) {Text(player.name)}
            ],
          )
       ]));
}

This results in the following error:

The element type 'Set' can't be assigned to the list type 'Widget'.

What am I doing wrong?

like image 237
Nimish David Mathew Avatar asked Oct 20 '19 08:10

Nimish David Mathew


1 Answers

You are creating a Set using the curly braces (set literal). Your build function should look exactly like this:

Widget build(BuildContext context) {
    return Container(
        child: Row(children: [
          Column(
            children: [
              for (var player in _players) Text(player.name)
            ],
          )
       ]));
}
like image 91
creativecreatorormaybenot Avatar answered Nov 15 '22 11:11

creativecreatorormaybenot