getRequestByIndex<T> method

T getRequestByIndex<T>(
  1. int index
)

Retrieves the result at the specified index with type safety.

Returns the result cast to type T. Results are stored in the same order as requests were submitted to zipRequest.

Example:

final firstResult = results.getRequestByIndex<UserInfo>(0);
final secondResult = results.getRequestByIndex<List<Product>>(1);

Throws:

  • RangeError if index is out of bounds [0, length)
  • The original error if the request at this index failed

See also:

Implementation

T getRequestByIndex<T>(int index) {
  if (index < 0 || index >= _results.length) {
    throw RangeError('Index $index out of range [0, ${_results.length})');
  }

  // Check if this request failed
  if (_errors.containsKey(index)) {
    throw _errors[index];
  }

  return _results[index] as T;
}