Skip to main content
1

๐Ÿ—บ๏ธ Mapping & Filtering

mapIndexed<R>(R Function(int index, T item) mapper)
List<R>
Maps the list, providing the elementโ€™s index along with the item to the mapper function. Perfect for generating indexed widgets.
final names = ['Alice', 'Bob'];
final widgets = names.mapIndexed((i, name) => Text('No. $i: $name'));
mapNotNull<R>(R? Function(T item) mapper)
List<R>
Maps the list and automatically filters out all resulting null values, guaranteeing a non-nullable output list.
final grades = [85, 40];
final passing = grades.mapNotNull((g) => g >= 50 ? g : null); // [85]
2

๐Ÿ”„ Sorting & Order

reversedList
List<T>
Gets a new list containing the elements of the original list in reverse order.
final original = [1, 2, 3];
final reversed = original.reversedList; // [3, 2, 1]
sortBy(Comparable Function(T) selector, {bool ascending})
void
Sorts the list in-place (mutates the original list) based on a selected property.
// Sorts by score in ascending order (10, 20)
users.sortBy((user) => user.score);
Mutates the original list
sortByAndReturnSorted(Comparable Function(T) selector, {bool ascending})
List<T>
Sorts the list based on a selected property and returns a new sorted list. The original list remains unchanged.
final originalScores = [10, 50, 20];
final topScores = originalScores.sortByAndReturnSorted((s) => s, ascending: false);
Returns a new sorted list. The original list remains unchanged.
3

โœ‚๏ธ Structural Changes

chunked(int chunkSize)
List<List<T>>
Splits the list into smaller sub-lists (chunks) of a maximum specified size. Highly useful for pagination or multi-column layouts.
final items = [1, 2, 3, 4, 5, 6, 7];
final chunks = items.chunked(3); // "chunks is [[1, 2, 3], [4, 5, 6], [7]]"