checkListIndex function

int checkListIndex(
  1. int index,
  2. int size, {
  3. dynamic message,
})

Throws a RangeError if the given index is not a valid index for a list with size elements. Otherwise, returns the index parameter.

Implementation

int checkListIndex(int index, int size, {message}) {
  if (index < 0 || index >= size) {
    throw RangeError(_resolveMessage(
        message, 'index $index not valid for list of size $size'));
  }
  return index;
}