fromJson static method
Returns a new KeyBinding instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static KeyBinding? 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(() {
assert(json.containsKey(r'id'), 'Required key "KeyBinding[id]" is missing from JSON.');
assert(json[r'id'] != null, 'Required key "KeyBinding[id]" has a null value in JSON.');
assert(json.containsKey(r'actionId'), 'Required key "KeyBinding[actionId]" is missing from JSON.');
assert(json[r'actionId'] != null, 'Required key "KeyBinding[actionId]" has a null value in JSON.');
return true;
}());
return KeyBinding(
id: mapValueOfType<String>(json, r'id')!,
actionId: mapValueOfType<String>(json, r'actionId')!,
displayName: mapValueOfType<String>(json, r'displayName'),
description: mapValueOfType<String>(json, r'description'),
key: mapValueOfType<String>(json, r'key'),
modifiers: json[r'modifiers'] is Iterable
? (json[r'modifiers'] as Iterable).cast<String>().toList(growable: false)
: const [],
category: mapValueOfType<String>(json, r'category'),
scope: mapValueOfType<String>(json, r'scope'),
displayOrder: mapValueOfType<int>(json, r'displayOrder'),
isCustom: mapValueOfType<bool>(json, r'isCustom'),
metadata: mapCastOfType<String, Object>(json, r'metadata') ?? const {},
);
}
return null;
}