fromJson static method

FlightDelayContract? fromJson(
  1. dynamic value
)

Returns a new FlightDelayContract instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static FlightDelayContract? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key),
            'Required key "FlightDelayContract[$key]" is missing from JSON.');
        assert(json[key] != null,
            'Required key "FlightDelayContract[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return FlightDelayContract(
      airportIcao: mapValueOfType<String>(json, r'airportIcao')!,
      class_: StatisticClass.fromJson(json[r'class'])!,
      medianDelay: mapValueOfType<String>(json, r'medianDelay')!,
      delayPercentiles:
          PercentileBracketContract.listFromJson(json[r'delayPercentiles']),
      numConsideredFlights:
          mapValueOfType<int>(json, r'numConsideredFlights')!,
      numFlightsDelayedBrackets: DelayBracketContract.listFromJson(
          json[r'numFlightsDelayedBrackets']),
      fromUtc: mapDateTime(json, r'fromUtc', r'')!,
      toUtc: mapDateTime(json, r'toUtc', r'')!,
      scheduledHourUtc: mapValueOfType<int>(json, r'scheduledHourUtc'),
    );
  }
  return null;
}