prefer_iterable_last
Severity | Quick Fix | Options |
---|---|---|
Info | ✅ | ❌ |
Details
DO use iterable.last
instead of iterable[iterable.length - 1]
or iterable.elementAt(iterable.length - 1)
.
Bad
const numbers = [1, 2, 3];
final lastNumber = numbers[numbers.length - 1];
// or
final lastNumber = numbers.elementAt(numbers.length - 1);
Good
const numbers = [1, 2, 3];
final lastNumber = numbers.last;