unnecessary_ to_ list_ in_ spreads
Unnecessary use of 'toList' in a spread.
Description
#
The analyzer produces this diagnostic when toList is used to convert an
Iterable to a List just before a spread operator is applied to the
list. The spread operator can be applied to any Iterable, so the
conversion isn't necessary.
Example
#
The following code produces this diagnostic because toList is invoked on
the result of map, which is an Iterable that the spread operator could
be applied to directly:
List<String> toLowercase(List<String> strings) {
return [
...strings.map((String s) => s.toLowerCase()).toList(),
];
}
Common fixes
#Remove the invocation of toList:
List<String> toLowercase(List<String> strings) {
return [
...strings.map((String s) => s.toLowerCase()),
];
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.