groupBy<K> method

Map<K, List<E>> groupBy<K>(
  1. K keyFunction(
    1. E item
    )
)

Flutter doesn't have built-in extensions for grouping items in a list, but you can use this extension to achieve your goals

Implementation

Map<K, List<E>> groupBy<K>(K Function(E item) keyFunction) {
  final Map<K, List<E>> result = {};
  for (final item in this) {
    final key = keyFunction(item);
    result.putIfAbsent(key, () => []).add(item);
  }
  return result;
}