class WeatherInfo { final String description; final double temperature; final double tempMin; final double tempMax; final int aqi; final String icon; final String city; const WeatherInfo({ required this.description, required this.temperature, required this.tempMin, required this.tempMax, required this.aqi, required this.icon, required this.city, }); factory WeatherInfo.fromJson(Map json) { final weather = (json["weather"] as List? ?? []).isNotEmpty ? json["weather"][0] as Map : {}; return WeatherInfo( description: weather["description"] as String? ?? "", temperature: (json["main"]?["temp"] as num?)?.toDouble() ?? 0, tempMin: (json["main"]?["temp_min"] as num?)?.toDouble() ?? 0, tempMax: (json["main"]?["temp_max"] as num?)?.toDouble() ?? 0, aqi: json["aqi"] as int? ?? 0, icon: weather["icon"] as String? ?? "", city: json["name"] as String? ?? "", ); } }