decodeArray method Null safety

List decodeArray (
  1. dynamic src
)

Decode an array

Implementation

List<dynamic> decodeArray(dynamic src) {
  var p = src is GsonParsable
      ? src
      : src is String
          ? GsonParsable(src)
          : throw ('The src is not a valid input to decode an Array from');
  var arr = [];
  var foundComma = true;
  if (p.next() != '[') {
    throw p.error('Array has to start with a [');
  }
  while (p.actual() != ']') {
    if (!foundComma) {
      throw p.error('Expected "]" or ","');
    }
    foundComma = false;
    _skipIgnored(p);
    if (RegExp(r'''[\\[\\{\\\"\\\'0-9]''').hasMatch(p.actual()) ||
        _PURE_STRING.hasMatch(p.actual())) {
      arr.add(decode(p));
    } else {
      throw p.error('Expected "[", "\\"","\\\'", "{" or a number');
    }
    _skipIgnored(p);
    if (p.actual() == ',') {
      foundComma = true;
      p.skip();
    }
    _skipIgnored(p);
  }
  if (!p.ended) {
    p.skip();
  }
  return arr;
}