I want to access weather data from api. the json is this: jsoncode
and the relevant part of my code is like this:
Future getWeather() async {
http.Response response = await http.get(
"http://api.openweathermap.org/data/2.5/onecall?lat=$lat&lon=$long&exclude=alerts&appid=apikey");
var results = jsonDecode(response.body);
setState(() {
this.temp = results['current']['temp'];
this.name = results['timezone'];
this.humidity = results['current']['humidity'];
this.description = results['current']['main'];
});
}
and this is the error i get:
E/flutter ( 9740): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
E/flutter ( 9740): Receiver: null
E/flutter ( 9740): Tried calling: []("temp")
and some extra lines of course.