项目场景:
报错:The method ‘cast’ was called on null
场景:异步获取接口信息,在widget里面调用
问题描述:
//获取商品
void _getGoodLlist() {
var pageData = {'page': page};
requestHttp('homePageHotShop', fromData: pageData).then((val) {
var data = json.decode(val.toString());
List<Map> newGoodList = (data['data'] as List).cast();
setState(() {
hotGoodItemList.addAll(newGoodList);
page++;
});
// print('${newGoodList}12313132');
});
}
void initState() {
super.initState();
_getGoodLlist();
print('home页面加载------------');
}
解决方案:
异步数据加载在initState()里面调用