Skip to content

Instantly share code, notes, and snippets.

@austinevick
Created September 8, 2022 11:28
Show Gist options
  • Save austinevick/fb0340af135a69cbdd76ae4f8b48f9d5 to your computer and use it in GitHub Desktop.
Save austinevick/fb0340af135a69cbdd76ae4f8b48f9d5 to your computer and use it in GitHub Desktop.
class WeatherModel {
final double latitude;
final double longitude;
WeatherModel({
required this.latitude,
required this.longitude,
});
}
class WeatherResponseModel {
String? cod;
int? message;
int? cnt;
List<Data>? list;
City? city;
WeatherResponseModel(
{this.cod, this.message, this.cnt, this.list, this.city});
WeatherResponseModel.fromJson(Map<String, dynamic> json) {
cod = json['cod'];
message = json['message'];
cnt = json['cnt'];
if (json['list'] != null) {
list = <Data>[];
json['list'].forEach((v) {
list!.add(Data.fromJson(v));
});
}
city = json['city'] != null ? City.fromJson(json['city']) : null;
}
}
class Data {
Main? main;
List<Weather>? weather;
Clouds? clouds;
DateTime? dtTxt;
Data({
this.weather,
this.clouds,
this.dtTxt,
});
Data.fromJson(Map<String, dynamic> json) {
main = json['main'] != null ? Main.fromJson(json['main']) : null;
if (json['weather'] != null) {
weather = <Weather>[];
json['weather'].forEach((v) {
weather!.add(Weather.fromJson(v));
});
}
clouds = json['clouds'] != null ? Clouds.fromJson(json['clouds']) : null;
dtTxt = DateTime.parse(json['dt_txt']);
}
}
class Main {
num? temp;
Main({
this.temp,
});
Main.fromJson(Map<String, dynamic> json) {
temp = json['temp'];
}
}
class Weather {
int? id;
String? main;
String? description;
String? icon;
Weather({this.id, this.main, this.description, this.icon});
Weather.fromJson(Map<String, dynamic> json) {
id = json['id'];
main = json['main'];
description = json['description'];
icon = json['icon'];
}
}
class Clouds {
int? all;
Clouds({this.all});
Clouds.fromJson(Map<String, dynamic> json) {
all = json['all'];
}
}
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});
City.fromJson(Map<String, dynamic> json) {
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});
Coord.fromJson(Map<String, dynamic> json) {
lat = json['lat'];
lon = json['lon'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment