elementAtOrNull method

T? elementAtOrNull(
  1. int index
)

Deprecation hint: Read the migration guide for more details on migrating.

Returns the indexth element. If the index is out of bounds it will return null.

Example:

['a', 'b'].elementAtOrNull(2); // null

Implementation

T? elementAtOrNull(int index) {
  try {
    return elementAt(index);
  } catch (error) {
    return null;
  }
}