elementAtOrNull method

E? elementAtOrNull(
  1. int index
)

Returns an element at the given index or null if the index is out of bounds of this list.

final list = [1, 2, 3, 4];
final first = list.elementAtOrNull(0); // 1
final fifth = list.elementAtOrNull(4); // null

Implementation

E? elementAtOrNull(int index) {
  if (index < 0) return null;
  if (index >= length) return null;
  return this[index];
}