Initial commit
This commit is contained in:
25
flutter_app/lib/models/weather_info.dart
Normal file
25
flutter_app/lib/models/weather_info.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
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? ?? "",
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user