【发布时间】:2018-05-29 08:02:45
【问题描述】:
我将此小部件附加到 Scaffold 正文。小部件获得一个返回 json 对象的 async 方法。
我想从该 json 对象动态构建一个列表。问题是屏幕是空的。由于某种原因,当列表准备好或类似的东西时,这个小部件需要刷新自己。
有什么想法吗?
class TestList extends StatelessWidget {
final quiz;
TestList({this.quiz});
@override
Widget build(BuildContext context) {
var listArray = [];
this.quiz.then((List value) { // this is a json object
// loop through the json object
for (var i = 0; i < value.length; i++) {
// add the ListTile to an array
listArray.add(new ListTile(title: new Text(value[i].name));
}
});
return new Container(
child: new ListView(
children: listArray // add the list here.
));
}
}
【问题讨论】:
标签: listview asynchronous flutter