Pageable class abstract

Represents a pagination request describing which slice of data should be retrieved from a paged resource.

A Pageable defines:

Two concrete implementations typically exist:

  • PageRequest — A fully defined, paginated request.
  • Unpaged — A sentinel representing “no pagination”.

This abstraction unifies pagination logic across repositories, query builders, and web controllers.

Usage Example

final pageable = PageRequest.of(0, 20, Sort.asc("username"));

print(pageable.getPageNumber()); // 0
print(pageable.getPageSize());   // 20
print(pageable.getSort());       // Sort([SortOrder(property=username, ...]])

final next = pageable.next();
print(next.getPageNumber());     // 1

Unpaged Example

final unpaged = Pageable.unpaged();
print(unpaged.isUnpaged()); // true
print(unpaged.getSort());   // Sort.UNSORTED

Design Notes

  • All page numbers are zero-based.
  • Unpaged instances represent unlimited queries (converted via toLimit).
  • Navigation methods always return new, immutable instances.
  • scrollPosition conversion uses exclusive semantics (offset - 1).

Example Behaviors

Condition Value
Pageable.unpaged() isPaged == false
PageRequest(...) isPaged == true
unpaged → toLimit Limit.unlimited()
paged → toLimit Limit.of(pageSize)

See Also

Mixed-in types
Implementers

Constructors

Pageable()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

equalizedProperties() → List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
inherited
getFirst() → Pageable
Returns a Pageable pointing to the first page (page 0).
getNext() → Pageable
Returns a new Pageable pointing to the next page in the sequence.
getOffset() → int
Returns the offset of the first element on the page.
getPageNumber() → int
Returns the zero-based page number.
getPageSize() → int
Returns the page size (number of elements per page).
getPreviousOrFirst() → Pageable
Returns the previous page if one exists, or the first page if currently at page 0.
getSort() → PageSort
Returns the sort configuration applied to this pagination request.
getSortOr(PageSort sort) → PageSort
Returns the sort defined on this instance, or falls back to the provided sort if this one is unsorted.
hasPrevious() → bool
Returns true if this pagination request has a previous page available.
isPaged() → bool
Indicates whether this instance represents a paged request.
isUnpaged() → bool
Indicates whether this instance represents an unpaged request.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
optional() → Optional<Pageable>
Returns an Optional containing this Pageable if it is paged, or empty if this represents an unpaged request.
toLimit() → Limit
Converts this pagination request into a Limit.
toScrollPosition() → OffsetPageScrollPosition
Converts this pagination request into an OffsetPageScrollPosition.
toString() → String
A string representation of this object.
inherited
withPage(int pageNumber) → Pageable
Returns a new Pageable with the given pageNumber.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

ofSize(int pageSize) → Pageable
Creates a paged request with the given pageSize, starting at page 0.
unpaged([PageSort? sort]) → Pageable
Creates an unpaged instance, optionally applying a sort.