getList<K> method

List<T> getList<K>(
  1. String key
)

This method retrieves the list associated with the given key from the map. If the key is not present or the value associated with the key is not a list, it returns an empty list of the generic type T.

@param key - a string key of the list you want to retrieve from the map

Example:

Map<String, dynamic> map = {'items': [1, 2, 3, 4], 'prices': [20.0, 30.0, 40.0]};

map.getList<int>('items') // returns [1, 2, 3, 4]
map.getList<double>('prices') // returns [20.0, 30.0, 40.0]
map.getList<int>('invalidKey') // returns []

Implementation

List<T> getList<K>(String key) =>
    containsKey(key) && this[key] is List<T> ? this[key]! as List<T> : <T>[];