基本上,当您在函数上单击“ return”时,该函数将停止并且不会继续进行迭代,因此您需要做的是将其全部放入列表中,然后将其添加为小部件的子级
您可以执行以下操作:
Widget getTextWidgets(List<String> strings)
{
List<Widget> list = new List<Widget>();
for(var i = 0; i < strings.length; i++){
list.add(new Text(strings[i]));
}
return new Row(children: list);
}
甚至更好,您可以使用.map()运算符并执行以下操作:
Widget getTextWidgets(List<String> strings)
{
return new Row(children: strings.map((item) => new Text(item)).toList());
}