fromJson static method

LeaderRow? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static LeaderRow? 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 "LeaderRow[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "LeaderRow[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return LeaderRow(
      ciHigh: num.parse('${json[r'ciHigh']}'),
      ciLow: num.parse('${json[r'ciLow']}'),
      claims: mapValueOfType<int>(json, r'claims'),
      gap: num.parse('${json[r'gap']}'),
      mean: num.parse('${json[r'mean']}'),
      measured: num.parse('${json[r'measured']}'),
      measuredAt: mapDateTime(json, r'measuredAt', r''),
      model: mapValueOfType<String>(json, r'model'),
      n: mapValueOfType<int>(json, r'n'),
      protocol: mapValueOfType<String>(json, r'protocol'),
      published: num.parse('${json[r'published']}'),
      run: mapValueOfType<String>(json, r'run'),
      spread: num.parse('${json[r'spread']}'),
    );
  }
  return null;
}