Files
bini-google-tv/flutter_app/lib/models/weather_info.dart
2026-01-24 19:41:19 +09:00

26 lines
713 B
Dart

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<String, dynamic> json) {
final weather = (json["weather"] as List<dynamic>? ?? []).isNotEmpty
? json["weather"][0] as Map<String, dynamic>
: {};
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? ?? "",
);
}
}