0

I have simple method like this:

List<Widget> stringsToWidgets( List<String>? a) {
    List<Text> b = [];
    for (var item in a) {
      b.add(Text(item));
    }
    return b;
  }
  Column(children: stringsToWidgets(["1", "2", "3"]));

I have column, and children of it come from this method. How to do it faster in place, without this stringsToWidgets method?

0

1 Answer 1

1

Ok, finally I found solution:

Column(
   children:
   for ( var i in ["1", "2", "3"] ) 
      Text(i)
);
Sign up to request clarification or add additional context in comments.

2 Comments

i is already a string, why do you have to add the .toString()?
You're right, I just test previously version of code where I had List<String?>? instead of List<String>? a

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.