OneCallDailyWeather.fromJson constructor
OneCallDailyWeather.fromJson(
- Map<
String, dynamic> json, - UnitSettings settings
JSON deserialization constructor
Implementation
factory OneCallDailyWeather.fromJson(
Map<String, dynamic> json,
UnitSettings settings,
) {
// Mapping the iconId and ID to a WeatherType enum
WeatherType weatherType = infoToWeatherType(
id: json['weather'][0]['id'],
iconId: json['weather'][0]['icon'],
);
// Formatting temperature
num? tempMorning = temperatureToSelectedUnit(
temp: json['temp']['morn'],
unit: settings.temperatureUnit,
);
// Formatting temperature
num? tempDay = temperatureToSelectedUnit(
temp: json['temp']['day'],
unit: settings.temperatureUnit,
);
// Formatting temperature
num? tempEvening = temperatureToSelectedUnit(
temp: json['temp']['eve'],
unit: settings.temperatureUnit,
);
// Formatting temperature
num? tempNight = temperatureToSelectedUnit(
temp: json['temp']['night'],
unit: settings.temperatureUnit,
);
// Formatting temperature
num? tempMin = temperatureToSelectedUnit(
temp: json['temp']['min'],
unit: settings.temperatureUnit,
);
// Formatting temperature
num? tempMax = temperatureToSelectedUnit(
temp: json['temp']['max'],
unit: settings.temperatureUnit,
);
// Formatting feels like temperature
num? feelsLikeTempMorning = temperatureToSelectedUnit(
temp: json['feels_like']['morn'],
unit: settings.temperatureUnit,
);
// Formatting feels like temperature
num? feelsLikeTempDay = temperatureToSelectedUnit(
temp: json['feels_like']['day'],
unit: settings.temperatureUnit,
);
// Formatting feels like temperature
num? feelsLikeTempEvening = temperatureToSelectedUnit(
temp: json['feels_like']['eve'],
unit: settings.temperatureUnit,
);
// Formatting feels like temperature
num? feelsLikeTempNight = temperatureToSelectedUnit(
temp: json['feels_like']['night'],
unit: settings.temperatureUnit,
);
// Formatting feels like temperature
num? dewPointTemp = temperatureToSelectedUnit(
temp: json['dew_point'],
unit: settings.temperatureUnit,
);
// Formatting the pressure
num pressure = pressureToSelectedUnit(
pressure: json['pressure'],
unit: settings.pressureUnit,
);
// Formatting the wind speed
num? windSpeed = windSpeedToSelectedUnit(
windSpeed: json['wind_speed'],
unit: settings.windSpeedUnit,
);
// Formatting the gust speed
num? windGustSpeed = windSpeedToSelectedUnit(
windSpeed: json['wind_gust'],
unit: settings.windSpeedUnit,
);
// Formatting the probability of precipitation
int? pop = (json['pop']) * 100;
int? precipitationChance = int.parse(pop!.toStringAsFixed(0));
// Formatting the amount of rain
num? rainAmount = precipitationToSelectedUnit(
amount: json['rain'],
unit: settings.precipitationUnit,
);
// Formatting the amount of snow
num? snowAmount = precipitationToSelectedUnit(
amount: json['snow'],
unit: settings.precipitationUnit,
);
return OneCallDailyWeather(
weatherID: json['weather'][0]['id'],
iconID: json['weather'][0]['icon'],
weatherType: weatherType,
mainDescription: json['weather'][0]['main'],
secondaryDescription: json['weather'][0]['description'],
tempMorning: tempMorning,
tempDay: tempDay,
tempEvening: tempEvening,
tempNight: tempNight,
tempMin: tempMin,
tempMax: tempMax,
feelsLikeTempMorning: feelsLikeTempMorning,
feelsLikeTempDay: feelsLikeTempDay,
feelsLikeTempEvening: feelsLikeTempEvening,
feelsLikeTempNight: feelsLikeTempNight,
dewPointTemp: dewPointTemp,
humidity: json['humidity'],
cloudiness: json['clouds'],
uvi: json['uvi'],
pressure: pressure,
windSpeed: windSpeed,
windDegree: json['wind_deg'],
windGustSpeed: windGustSpeed,
precipitationChance: precipitationChance,
rainAmount: rainAmount,
snowAmount: snowAmount,
sunrise: DateTime.fromMillisecondsSinceEpoch(
(json['sunrise']) * 1000,
isUtc: true,
),
sunset: DateTime.fromMillisecondsSinceEpoch(
(json['sunset']) * 1000,
isUtc: true,
),
moonrise: DateTime.fromMillisecondsSinceEpoch(
(json['moonrise']) * 1000,
isUtc: true,
),
moonset: DateTime.fromMillisecondsSinceEpoch(
(json['moonset']) * 1000,
isUtc: true,
),
moonPhase: json['moon_phase'],
timeStamp: DateTime.fromMillisecondsSinceEpoch(
(json['dt']) * 1000,
isUtc: true,
),
);
}