Flutter http.get无法执行

MedNader Ghorghar

我刚接触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执行中。

MedNader Ghorghar

通过运行Flutter clean解决仍然不知道如何

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章