getWeather method

Future<WeatherModel?> getWeather({
  1. required double latitude,
  2. required double longitude,
  3. required String apiKey,
})

Implementation

Future<WeatherModel?> getWeather(
    {required double latitude,
    required double longitude,
    required String apiKey}) async {
  _endpoint =
      "https://api.openweathermap.org/data/2.5/onecall?lat=$latitude&lon=$longitude&exclude=hourly,minutely,alerts&appid=$apiKey&units=metric";
  try {
    Response response = await _dio.get(_endpoint);
    return WeatherModel.fromJson(response.data);
  } catch (error, stacktrace) {
    print("Exception occured: $error stackTrace: $stacktrace");
    // return WeatherModel.withError("$error");
  }
}