class WeatherInfo { final String description; final double temperature; final String icon; final String city; const WeatherInfo({ required this.description, required this.temperature, 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, icon: weather["icon"] as String? ?? "", city: json["name"] as String? ?? "", ); } }