getRequestByIndex<T> method
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
indexis out of bounds [0, length) - The original error if the request at this index failed
See also:
- getRequestByTag for tag-based access
- isSuccess to check if a request succeeded before accessing
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;
}