【发布时间】:2019-05-07 16:17:17
【问题描述】:
我正在从 Dart 中的 json 数据填充一个数组
String url="http://someapi.com/words";
List<Word> words=new List<Word>();
final res = await http.get(url, headers: {"Accept": "aplication/json"});
final wordsList = json.decode(res.body);
for (var h in wordsList) {
Word word = new Word(title: h['title'].toString());
words.add(word);
}
这给了我一个单词列表。现在如何在小部件中使用它? 以下是我目前拥有的代码
@override
Widget build(BuildContext context) {
final response=fetchWords(); //this response will have list of words
return new Container(
padding: new EdgeInsets.symmetric(vertical: 15.0,
horizontal: 15.0),
child: Column(children: <Widget>[
new Row(
children: <Widget>[
//I want to add a container for each for words here
],
)
])
);
我尝试关注this,但我不确定如何将 json 数组转换为小部件
【问题讨论】: