materializeRange method

List materializeRange(
  1. Object? left,
  2. Object? right, {
  3. int offset = 0,
  4. int? limit,
})

Builds the inclusive range or a requested window of it.

Implementation

List<dynamic> materializeRange(
  Object? left,
  Object? right, {
  int offset = 0,
  int? limit,
}) {
  final start = _rangeEndpoint(left);
  final end = _rangeEndpoint(right);
  if (end < start || (limit != null && limit <= 0)) return [];
  // Use exact arithmetic so distant endpoints cannot wrap the length before
  // the window and allocation limit are applied.
  final first = BigInt.from(start) + BigInt.from(offset < 0 ? 0 : offset);
  final last = BigInt.from(end);
  if (first > last) return [];
  var count = last - first + BigInt.one;
  if (limit != null && count > BigInt.from(limit)) count = BigInt.from(limit);
  final maxSize = context.maxRangeSize;
  if (maxSize != null && count > BigInt.from(maxSize)) {
    throw RangeError('Range exceeds the maximum of $maxSize items.');
  }
  if (!count.isValidInt) throw RangeError('Range is too large.');
  final firstValue = first.toInt();
  return List<dynamic>.generate(count.toInt(), (index) => firstValue + index);
}