【发布时间】:2019-08-24 18:21:13
【问题描述】:
我该如何解决这个问题 我使用函数从 api 获取数据,但我看到错误 'NoSuchMethodError: The getter 'length' was called on null'
我的代码:
Future getData() async{
http.Response response = await http.get('https://myappres.000webhostapp.com/pubg/api.php?action=getskin');
debugPrint(response.body);
_data = json.decode(response.body);
_list = _data['categorys'];
return _list;
}
和
Center(
child: _list.length != null? ListView.builder(
itemCount: _list.length,
padding: const EdgeInsets.all(15.9),
itemBuilder: (BuildContext context, int position){
final index = position;
return ListTile(
title: Text('${_list[index]['name']}'),
subtitle: Image.network('${_list[index]['image']}',width: 200,)
);
}
):Container()
)
【问题讨论】:
标签: flutter