【发布时间】:2020-02-12 09:04:07
【问题描述】:
我尝试获取 api json ,这是链接https://api.myjson.com/bins/ut9kq 当我在循环之前打印输出时,它确实得到了数据,但在列表之后它给了我错误
“未处理的异常:NoSuchMethodError:在 null 上调用了 getter 'image'。 E/颤振(30730):接收器:空 E/flutter (30730): 尝试调用:image"
这是我的代码
List lists;
Future<List> getLists() async {
lists = new List();
await api.httpGet('bins/ut9kq').then((reponse) {
var data = jsonDecode(reponse.body);
print(data); // i get the json data => [{},{}..]
data.forEach((l) {
lists.add(ArticleModal().fromJson(l));
});
// print(lists[0].image);//Receiver: null
});
return lists;
}
【问题讨论】:
-
好吧,我一直在使用它,它就像魅力一样工作。我没有看到任何区别(而不是调用模型并为其设置名称),是否存在性能问题?跨度>
标签: json flutter dart fetch flutter-layout