我刚接触Flutter
,并遇到以下问题:
child: RaisedButton(
onPressed: () {
fetchData();
},
// ...
fetchData() async {
final res = await http.get("https://jsonplaceholder.typicode.com/posts");
if (res.statusCode == 200) {
// If the call to the server was successful, parse the JSON
print("it works");
return json.decode(res.body);
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load post');
}
}
// ...
当我删除http.get部分时,它会打印“有效”,因此我认为问题出在http.get执行中。
通过运行Flutter clean解决仍然不知道如何
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句