getCurrentWeather method

Future<WeatherData> getCurrentWeather({
  1. required double latitude,
  2. required double longitude,
})

//////////// //////////// Fetches current weather data for a specific location

Implementation

// V.C - Weather Retrieval Methods
///////////////
/// Fetches current weather data for a specific location
Future<WeatherData> getCurrentWeather({
  required double latitude,
  required double longitude
}) async {
  try {
    final url = Uri.https(_baseUrl, '/data/2.5/weather', {
      'lat': latitude.toString(),
      'lon': longitude.toString(),
      'appid': apiKey,
      'units': 'metric', // Use Celsius
    });

    final response = await http.get(url);

    if (response.statusCode == 200) {
      final jsonData = json.decode(response.body);
      return WeatherData.fromJson(jsonData);
    } else {
      throw HttpException('Failed to fetch weather data: ${response.statusCode}');
    }
  } catch (e) {
    print('Weather API error: $e');
    rethrow;
  }
}