decodeJsonTree method
Converts json
(any JSON tree) to an instance of T
.
Throws ArgumentError if the JSON does not match.
Implementation
@override
T decodeJsonTree(Object? json) {
final values = this.byName;
if (json is String) {
final value = byName[json];
if (value != null) {
return value;
}
} else if (json is num) {
final searchedIndex = json.toInt();
if (json >= 0 && json < values.length) {
var i = 0;
for (var item in byName.values) {
if (i == searchedIndex) {
return item;
}
i++;
}
}
}
throw ArgumentError.value(json);
}