Open imacro1212 opened 4 months ago
are there any errors in the debug log?
same issue no log related
Same error: If it helps these are the console logs:
I/flutter ( 4481): Fetched Weather for: Mountain View/US
I/flutter ( 4481): NoSuchMethodError: The method '[]' was called on null.
I/flutter ( 4481): Receiver: null
I/flutter ( 4481): Tried calling: [](0)
Ah.. I think I figured this out. The OneCall API needs a different API key, which needs billing enabled.
Uri dailyUrl = Uri.parse(
'https://api.openweathermap.org/data/2.5/onecall?lat=${location.latitude}&lon=${location.longitude}&units=metric&exclude=minutely,current&appid=$apiKey',
);
A minor change to add API checks would sort this out. Some quick bad coding.. but here it is:
...
final response = await http.get(dailyUrl);
if (response.statusCode == 401) {
print('Authentication error: 401 Unauthorized');
isLoading = false;
isRequestError = true;
return;
}
final dailyData = json.decode(response.body) as Map<String, dynamic>;
....
OR
Just subscribe to OneCall 3.0: https://openweathermap.org/api/one-call-3 and give it some time to register and then change the URL to something like this:
Uri dailyUrl = Uri.parse(
'https://api.openweathermap.org/data/3.0/onecall?lat=${location.latitude}&lon=${location.longitude}&units=metric&exclude=minutely,current&appid=$apiKey',
);
Ah.. I think I figured this out. The OneCall API needs a different API key, which needs billing enabled.
Uri dailyUrl = Uri.parse( 'https://api.openweathermap.org/data/2.5/onecall?lat=${location.latitude}&lon=${location.longitude}&units=metric&exclude=minutely,current&appid=$apiKey', );
A minor change to add API checks would sort this out. Some quick bad coding.. but here it is:
... final response = await http.get(dailyUrl); if (response.statusCode == 401) { print('Authentication error: 401 Unauthorized'); isLoading = false; isRequestError = true; return; } final dailyData = json.decode(response.body) as Map<String, dynamic>; ....
OR
Just subscribe to OneCall 3.0: https://openweathermap.org/api/one-call-3 and give it some time to register and then change the URL to something like this:
Uri dailyUrl = Uri.parse( 'https://api.openweathermap.org/data/3.0/onecall?lat=${location.latitude}&lon=${location.longitude}&units=metric&exclude=minutely,current&appid=$apiKey', );
Hmmm that's weird, my billing is turned off and I'm using the OneCall version 2.5 as stated in the readme. I will double check again it could be a regional thing. in the meantime when I have the time I will try to update the code to handle it
Thanks, but the app shows request error, please check your internet connection page. I added my working api key and checked internet permission and the problem still exist. Thanks again.