subsequenceFromPage method Null safety

MessageSequence subsequenceFromPage(
  1. int pageNumber,
  2. int pageSize,
  3. {int skip = 0}
)

Retrieves sequence containing the message IDs/UIDs from the page with the given pageNumber which starts at 1 and the given pageSize.

This pages start from the end of this sequence, optionally skipping the first skip entries. When the pageNumber is 1 and the pageSize is equals or bigger than the length of this sequence, this sequence is returned.

Implementation

MessageSequence subsequenceFromPage(int pageNumber, int pageSize,
    {int skip = 0}) {
  if (pageNumber == 1 && pageSize >= length) {
    return this;
  }
  final pageIndex = pageNumber - 1;
  final end = length - skip - (pageIndex * pageSize);
  if (end <= 0) {
    return MessageSequence();
  }
  var start = end - pageSize;
  if (start < 0) {
    start = 0;
  }
  return subsequence(start, end);
}