getOrNull method

T? getOrNull(
  1. int index
)

Returns the element of position index of the list or null if index is out of bounds.

Note: beware that using this on a non-List Iterable this will have to iterate the list, similar to elementAt.

Implementation

T? getOrNull(int index) {
  if (index >= 0 && index < length) {
    return elementAt(index);
  }
  return null;
}