Uint8ClampedList.sublistView constructor Null safety
- @Since("2.8")
Creates a Uint8ClampedList view on a range of elements of data
.
Creates a view on the range of data.buffer
which corresponds
to the elements of data
from start
until end
.
If data
is a typed data list, like Uint16List, then the view is on
the bytes of the elements with indices from start
until end
.
If data
is a ByteData, it's treated like a list of bytes.
If provided, start
and end
must satisfy
0 ≤ start
≤ end
≤ elementCount
where elementCount is the number of elements in data
, which
is the same as the List.length of a typed data list.
If omitted, start
defaults to zero and end
to elementCount.
Implementation
@Since("2.8")
factory Uint8ClampedList.sublistView(TypedData data,
[int start = 0, int? end]) {
int elementSize = data.elementSizeInBytes;
end = RangeError.checkValidRange(
start, end, data.lengthInBytes ~/ elementSize);
if (end == null) throw "unreachable"; // TODO(38725)
return data.buffer.asUint8ClampedList(
data.offsetInBytes + start * elementSize, (end - start) * elementSize);
}