elementAtOrDefault method
Returns an element at the given index
or defaultValue
if the index
is out of bounds of this collection.
final list = [1, 2, 3, 4];
final first = list.elementAtOrDefault(0, -1); // 1
final fifth = list.elementAtOrDefault(4, -1); // -1
Implementation
E elementAtOrDefault(int index, E defaultValue) {
return elementAtOrElse(index, (_) => defaultValue);
}