fromJson static method
Returns a new TrafficView instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static TrafficView? 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 "TrafficView[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "TrafficView[$key]" has a null value in JSON.');
});
return true;
}());
return TrafficView(
blind: mapValueOfType<int>(json, r'blind'),
callers: TrafficCaller.listFromJson(json[r'callers']),
ceiling: mapValueOfType<int>(json, r'ceiling'),
denied: mapValueOfType<int>(json, r'denied'),
lanes: mapCastOfType<String, int>(json, r'lanes') ?? const {},
mode: mapValueOfType<String>(json, r'mode'),
org: mapValueOfType<String>(json, r'org'),
refused: mapValueOfType<int>(json, r'refused'),
requests: mapValueOfType<int>(json, r'requests'),
screens: mapValueOfType<int>(json, r'screens'),
strain: mapValueOfType<String>(json, r'strain'),
tracked: mapValueOfType<int>(json, r'tracked'),
unscored: mapValueOfType<int>(json, r'unscored'),
windowSec: mapValueOfType<int>(json, r'window_sec'),
);
}
return null;
}