218 lines
4.4 KiB
Dart
218 lines
4.4 KiB
Dart
class WeatherData {
|
|
String? cod;
|
|
int? message;
|
|
int? cnt;
|
|
List<WeatherForecast>? list;
|
|
City? city;
|
|
|
|
WeatherData({this.cod, this.message, this.cnt, this.list, this.city});
|
|
|
|
factory WeatherData.fromJson(Map<String, dynamic> json) {
|
|
return WeatherData(
|
|
cod: json['cod'],
|
|
message: json['message'],
|
|
cnt: json['cnt'],
|
|
list: (json['list'] as List?)?.map((item) => WeatherForecast.fromJson(item)).toList(),
|
|
city: json['city'] != null ? City.fromJson(json['city']) : null,
|
|
);
|
|
}
|
|
}
|
|
|
|
class WeatherForecast {
|
|
int? dt;
|
|
MainWeatherData? main;
|
|
List<Weather>? weather;
|
|
Clouds? clouds;
|
|
Wind? wind;
|
|
int? visibility;
|
|
dynamic pop;
|
|
Rain? rain;
|
|
Sys? sys;
|
|
String? dtTxt;
|
|
|
|
WeatherForecast({
|
|
this.dt,
|
|
this.main,
|
|
this.weather,
|
|
this.clouds,
|
|
this.wind,
|
|
this.visibility,
|
|
this.pop,
|
|
this.rain,
|
|
this.sys,
|
|
this.dtTxt,
|
|
});
|
|
|
|
factory WeatherForecast.fromJson(Map<String, dynamic> json) {
|
|
return WeatherForecast(
|
|
dt: json['dt'],
|
|
main: json['main'] != null ? MainWeatherData.fromJson(json['main']) : null,
|
|
weather: (json['weather'] as List?)?.map((item) => Weather.fromJson(item)).toList(),
|
|
clouds: json['clouds'] != null ? Clouds.fromJson(json['clouds']) : null,
|
|
wind: json['wind'] != null ? Wind.fromJson(json['wind']) : null,
|
|
visibility: json['visibility'],
|
|
pop: json['pop'],
|
|
rain: json['rain'] != null ? Rain.fromJson(json['rain']) : null,
|
|
sys: json['sys'] != null ? Sys.fromJson(json['sys']) : null,
|
|
dtTxt: json['dt_txt'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class MainWeatherData {
|
|
double? temp;
|
|
double? feelsLike;
|
|
double? tempMin;
|
|
double? tempMax;
|
|
int? pressure;
|
|
int? seaLevel;
|
|
int? grndLevel;
|
|
int? humidity;
|
|
double? tempKf;
|
|
|
|
MainWeatherData({
|
|
this.temp,
|
|
this.feelsLike,
|
|
this.tempMin,
|
|
this.tempMax,
|
|
this.pressure,
|
|
this.seaLevel,
|
|
this.grndLevel,
|
|
this.humidity,
|
|
this.tempKf,
|
|
});
|
|
|
|
factory MainWeatherData.fromJson(Map<String, dynamic> json) {
|
|
return MainWeatherData(
|
|
temp: json['temp']?.toDouble(),
|
|
feelsLike: json['feels_like']?.toDouble(),
|
|
tempMin: json['temp_min']?.toDouble(),
|
|
tempMax: json['temp_max']?.toDouble(),
|
|
pressure: json['pressure'],
|
|
seaLevel: json['sea_level'],
|
|
grndLevel: json['grnd_level'],
|
|
humidity: json['humidity'],
|
|
tempKf: json['temp_kf']?.toDouble(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class Weather {
|
|
int? id;
|
|
String? main;
|
|
String? description;
|
|
String? icon;
|
|
|
|
Weather({this.id, this.main, this.description, this.icon});
|
|
|
|
factory Weather.fromJson(Map<String, dynamic> json) {
|
|
return Weather(
|
|
id: json['id'],
|
|
main: json['main'],
|
|
description: json['description'],
|
|
icon: json['icon'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class Clouds {
|
|
int? all;
|
|
|
|
Clouds({this.all});
|
|
|
|
factory Clouds.fromJson(Map<String, dynamic> json) {
|
|
return Clouds(
|
|
all: json['all'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class Wind {
|
|
double? speed;
|
|
int? deg;
|
|
double? gust;
|
|
|
|
Wind({this.speed, this.deg, this.gust});
|
|
|
|
factory Wind.fromJson(Map<String, dynamic> json) {
|
|
return Wind(
|
|
speed: json['speed']?.toDouble(),
|
|
deg: json['deg'],
|
|
gust: json['gust']?.toDouble(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class Rain {
|
|
double? h3;
|
|
|
|
Rain({this.h3});
|
|
|
|
factory Rain.fromJson(Map<String, dynamic> json) {
|
|
return Rain(
|
|
h3: json['3h']?.toDouble(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class Sys {
|
|
String? pod;
|
|
|
|
Sys({this.pod});
|
|
|
|
factory Sys.fromJson(Map<String, dynamic> json) {
|
|
return Sys(
|
|
pod: json['pod'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class City {
|
|
int? id;
|
|
String? name;
|
|
Coord? coord;
|
|
String? country;
|
|
int? population;
|
|
int? timezone;
|
|
int? sunrise;
|
|
int? sunset;
|
|
|
|
City({
|
|
this.id,
|
|
this.name,
|
|
this.coord,
|
|
this.country,
|
|
this.population,
|
|
this.timezone,
|
|
this.sunrise,
|
|
this.sunset,
|
|
});
|
|
|
|
factory City.fromJson(Map<String, dynamic> json) {
|
|
return City(
|
|
id: json['id'],
|
|
name: json['name'],
|
|
coord: json['coord'] != null ? Coord.fromJson(json['coord']) : null,
|
|
country: json['country'],
|
|
population: json['population'],
|
|
timezone: json['timezone'],
|
|
sunrise: json['sunrise'],
|
|
sunset: json['sunset'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class Coord {
|
|
double? lat;
|
|
double? lon;
|
|
|
|
Coord({this.lat, this.lon});
|
|
|
|
factory Coord.fromJson(Map<String, dynamic> json) {
|
|
return Coord(
|
|
lat: json['lat']?.toDouble(),
|
|
lon: json['lon']?.toDouble(),
|
|
);
|
|
}
|
|
}
|