OneCallWeather.fromJson constructor

OneCallWeather.fromJson(
  1. Map<String, dynamic> json,
  2. UnitSettings settings
)

JSON deserialization constructor

Implementation

factory OneCallWeather.fromJson(
  Map<String, dynamic> json,
  UnitSettings settings,
) {
  // Looping through the array of minutely weather JSON and parsing them into a list
  List? minutelyPayload = json['minutely'];
  List<OneCallMinutelyWeather?>? minutelyWeather = minutelyPayload!.map(
    (e) {
      return OneCallMinutelyWeather.fromJson(
        e,
        settings,
      );
    },
  ).toList();

  // Looping through the array of hourly weather JSON and parsing them into a list
  List? hourlyPayload = json['hourly'];
  List<OneCallHourlyWeather?>? hourlyWeather = hourlyPayload!.map(
    (e) {
      return OneCallHourlyWeather.fromJson(
        e,
        settings,
      );
    },
  ).toList();

  // Looping through the array of daily weather JSON and parsing them into a list
  List? dailyPayload = json['daily'];
  List<OneCallDailyWeather?>? dailyWeather = dailyPayload!.map((e) {
    return OneCallDailyWeather.fromJson(
      e,
      settings,
    );
  }).toList();

  return OneCallWeather(
    locationCoords: LocationCoords(
      latitude: json['lat'],
      longitude: json['lon'],
    ),
    timeZoneName: json['timezone'],
    timeZoneOffset: json['timezone_offset'],
    currentWeather: OneCallCurrentWeather.fromJson(
      json['current'],
      settings,
    ),
    minutelyWeather: minutelyWeather,
    hourlyWeather: hourlyWeather,
    dailyWeather: dailyWeather,
    alertsWeather: OneCallAlertsWeather.fromJson(
      json['alerts'],
      settings,
    ),
  );
}