decode method Null safety
- dynamic gson
Insert gson to decode
Implementation
dynamic decode(dynamic gson) {
var p = gson is GsonParsable
? gson
: gson is String
? GsonParsable(gson)
: throw ('The gson is not a valid input to decode an Array from');
if (p.actual() == '{') {
return decodeMap(p);
} else if (p.actual() == '[') {
return decodeArray(p);
} else if (p.actual() == 't' &&
p.peek(1) == 'r' &&
p.peek(2) == 'u' &&
p.peek(3) == 'e') {
return true;
} else if (p.actual() == 'f' &&
p.peek(1) == 'a' &&
p.peek(2) == 'l' &&
p.peek(3) == 's' &&
p.peek(4) == 'e') {
return false;
} else if (RegExp(r'[0-9\.]').hasMatch(p.actual())) {
return decodeNumber(p);
} else if (p.actual() == '"' ||
p.actual() == "'" ||
_PURE_STRING.hasMatch(p.actual())) {
return decodeString(p);
} else {
throw p.error('Unexpected character ' + p.actual());
}
}