toList<T> method

List<T>? toList<T>(
  1. dynamic key,
  2. T mapper(
    1. dynamic item
    ),
  3. {List<T>? fallback}
)

Tries to parse a Map with the provided key into a list returns fallback if the key doesn't exist in the map OR the KVP is not of a list type

Implementation

List<T>? toList<T>(dynamic key, T Function(dynamic item) mapper,
    {List<T>? fallback}) {
  if (!this.hasValue(key)) return fallback;

  if (this[key] is List) {
    return (this[key] as List).map((item) => mapper(item)).toList();
  }

  return fallback;
}