parseList<T> static method

List<T>? parseList<T>(
  1. Object? value, {
  2. List<T>? def,
  3. TypeElementParser<T>? elementParser,
})

Tries to parse a List.

  • Returns def if value is null or an empty String.
  • elementParser is an optional parser for the elements of the parsed List.

Implementation

static List<T>? parseList<T>(Object? value,
    {List<T>? def, TypeElementParser<T>? elementParser}) {
  if (value == null) return def;

  var l = _parseListImpl(value);
  if (l == null) return def;

  if (elementParser != null) {
    l = l.map(elementParser).toList();
  }

  if (l is List<T>) {
    return l;
  } else if (elementParser != null) {
    l = l.whereType<T>().toList();
  } else {
    var parser = parserFor<T>();
    if (parser != null) {
      l = l.map(parser).toList();
    }
  }

  if (l is List<T>) {
    return l;
  } else {
    return l.whereType<T>().toList();
  }
}