-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed ocassional API error on first refresh, moved networking out of …
…weather class
- Loading branch information
Showing
5 changed files
with
42 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
import 'dart:convert' as convert; | ||
|
||
import 'package:http/http.dart' as http; | ||
import 'package:http/http.dart'; | ||
import 'package:weatherapp/credentials.dart'; | ||
import 'package:weatherapp/constants.dart'; | ||
|
||
String key = apiKey; | ||
|
||
//ToDo: Currently unused due to it needing required, and the URL in the method that evokes it | ||
class NetworkService{ | ||
final String url; | ||
NetworkService(String s, {required this.url}); | ||
|
||
Future fetchAPI(String url) async{ | ||
final response = await http.get(url as Uri); | ||
String key = apiKey; | ||
|
||
if(response.statusCode == 200){ | ||
return convert.jsonDecode(response.body); | ||
} else{ | ||
throw Exception('Failed to fetch API'); | ||
} | ||
Future<Response> getCurrentTemperature(locationData) async{ | ||
Response response = await get( | ||
//One call API. Returns more data than the standard data | ||
Uri.parse( | ||
'$openWeatherURL?lat=${locationData.latitude}&lon=${locationData.longitude}&exclude=&appid=$apiKey&units=$appUnits&lang=$appLang' | ||
) | ||
); | ||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters