elementAtOrNull method

T? elementAtOrNull(
  1. int index
)

Gets an element at a specific index or returns null if the index is out of bounds.

Example:

Iterable<int>? numbers = [1, 2, 3];
int? result = numbers.elementAtOrNull(1);  // 2

Implementation

T? elementAtOrNull(int index) {
  if (isNullOrEmpty) {
    return null;
  }
  if (index < this!.length) {
    return this!.elementAt(index);
  } else {
    return null;
  }
}