如何使用“为"在小部件的子项内部循环? [英] How to use a "for" loop inside children of a widget?

查看:28
本文介绍了如何使用“为"在小部件的子项内部循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此感到非常困惑,应该将FOR LOOP放在哪里,这样我就不会在抖动中出错了?正如您在图片上看到的那样,它带有红色下划线,并且上面写着.

I am really confused with this, where should the FOR LOOP be placed, so that I don't get an error in flutter? As you can see on the picture, it has red underlines and it says.

推荐答案

两种选择:

final children = <Widget>[];
for (var i = 0; i < 10; i++) {
  children.add(new ListTile());
}
return new ListView(
  children: children,
);

return new ListView(
  children: new List.generate(10, (index) => new ListTile()),
);

这篇关于如何使用“为"在小部件的子项内部循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆