Skip to content

Instantly share code, notes, and snippets.

@austinevick
Last active September 8, 2022 11:58
Show Gist options
  • Save austinevick/f97f96909d4e23bb9ed32c7686645855 to your computer and use it in GitHub Desktop.
Save austinevick/f97f96909d4e23bb9ed32c7686645855 to your computer and use it in GitHub Desktop.
final weatherServiceProvider = Provider((ref) => WeatherServiceImpl());
abstract class WeatherService {
Future getWeather(WeatherModel model);
}
class WeatherServiceImpl extends WeatherService {
final _client = Client();
const baseUrl = "https://api.openweathermap.org/data/";
const version = '2.5/';
const apikey = '';
@override
Future<WeatherResponseModel> getWeather(WeatherModel model) async {
final response = await _client.get(Uri.parse(
"$baseUrl${version}forecast?lat=${model.latitude}&lon=${model.longitude}&appid=$apikey"));
final data = jsonDecode(response.body);
print(data);
return WeatherResponseModel.fromJson(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment