parseListOfStrings function

List<String> parseListOfStrings(
  1. Object? s,
  2. Pattern delimiter, [
  3. bool trim = true
])

Parses s as a flat List<String>.

s If is a String uses delimiter to split strings. If s is a List iterator over it and flatten sub lists. delimiter Pattern to split s to list. trim If true trims all strings.

Implementation

List<String> parseListOfStrings(Object? s, Pattern delimiter,
    [bool trim = true]) {
  if (s == null) return <String>[];

  List<String> list;

  if (s is List) {
    list = s.map(parseString).whereType<String>().toList();
  } else {
    var str = parseString(s, '')!;
    if (trim) str = str.trim();
    list = str.split(delimiter);
  }

  if (trim) {
    list = list.map((e) => e.trim()).where((e) => e.isNotEmpty).toList();
  }

  return list;
}