Search code examples
androidflutterdartopenweathermap

Why does flutter API response body not print in console?


I am trying to send an API request using dart http package. I am new to developing in flutter (but I have coded extensively in java however). I was wondering why the response body would not print in the console. I added the dependency in the pubscpec.yaml and imported in the top of the page. There is no issue with the importing as I get no error when running (no words having any red lines and correctly autocompletes)
Here is the code to the function used to send the request

void getData() async {
    var url = Uri.parse("http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=110a603f26f6f7e2ade19f00669dc8fa");
    var response = await http.get(url);
    print('Response body: ${response.body}');
  }

Note: the API key is the default developer key provided by openweathermap
When I run, I get no error, just a clean console, nothing is printed under the run tab
Thank you!


Solution

  • you can open flutter dev tool and under the network tab check whether you are getting response or not, may be that await never finished and execution never reached the print statement, so it doesn't get printed