我想将从方法“getData()”返回的数据获取到列表“datat”中,但出现此错误:“方法“[]”被调用为空“
这是相应的代码:
ListeMedecinsState() {
/* Fetching Data Into ListView */
Future<String> getData() async {
var response = await http.get(
Uri.encodeFull("http://10.0.2.2:4000/user/GetAllMedecins"),
headers: {
"Accept": "application/json"
}
);
this.setState(() {
this.data = json.decode(response.body);
});
return "Success";
}
getData() ;
print(this.data[1]["email"]);
/* Fetching Data Into ListView */
}
注意:当我将数据检索到方法内的列表中时,它没有显示错误,我想使用方法范围之外的数据,我该怎么做?
另外,你可以这样做:
getData().then((data){
//do something with data
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句