'openweathermap flutter call for local condtions. I get error type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'

void getData() async { http.Response response = await http.get(Uri.parse( 'https://api.openweathermap.org/data/2.5/weather?lat=$latitude&lon=$longitude&appid=$apiKey'));

if (response.statusCode == 200) {
  String data = response.body;
  var decodedData = jsonDecode(data);

  String city = jsonDecode(decodedData)['name'];
  double temperature = jsonDecode(decodedData)['main']['temp'];
  int condition = jsonDecode(decodedData)['weather'][0]['id'];

  print(city);
  print(temperature);
  print(condition);
} else {
  print(response.statusCode);
}

}



Solution 1:[1]

Solved. I was using code from a tutorial that was about a year old. I followed the flutter docs to solve this problem by creating a WeatherData class with the city, temperature and condition properties and called the http request through the WeatherData class. It worked without errors

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jsmith