PaginatorModel class

A paginator widget for handling pagination state and rendering.

The paginator manages page state and provides rendering for pagination indicators. It can display pages as Arabic numerals ("1/10") or dots ("●○○").

Example

class ListModel implements Model {
  final List<String> items;
  final PaginatorModel paginator;

  ListModel({required this.items, PaginatorModel? paginator})
      : paginator = paginator ?? PaginatorModel(perPage: 10)
          ..setTotalPages(items.length);

  @override
  (Model, Cmd?) update(Msg msg) {
    final (newPaginator, cmd) = paginator.update(msg);
    return (
      ListModel(items: items, paginator: newPaginator as PaginatorModel),
      cmd,
    );
  }

  @override
  String view() {
    final (start, end) = paginator.getSliceBounds(items.length);
    final visibleItems = items.sublist(start, end);
    return '''
${visibleItems.map((i) => '• $i').join('\n')}

${paginator.view()}
''';
  }
}
Inheritance

Constructors

PaginatorModel({PaginationType type = PaginationType.arabic, int page = 0, int perPage = 1, int totalPages = 1, String activeDot = PaginationDots.active, String inactiveDot = PaginationDots.inactive, String arabicFormat = '%d/%d', PaginatorKeyMap? keyMap})
Creates a new paginator model.

Properties

activeDot → String
Character for the active page dot.
final
arabicFormat → String
Format string for Arabic pagination (e.g., "%d/%d").
final
hashCode → int
The hash code for this object.
no setterinherited
inactiveDot → String
Character for inactive page dots.
final
keyMap → PaginatorKeyMap
Key bindings for navigation.
final
onFirstPage → bool
Whether we're on the first page.
no setter
onLastPage → bool
Whether we're on the last page.
no setter
page → int
The current page (0-indexed).
final
perPage → int
Number of items per page.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
totalPages → int
Total number of pages.
final
type → PaginationType
The type of pagination display.
final

Methods

copyWith({PaginationType? type, int? page, int? perPage, int? totalPages, String? activeDot, String? inactiveDot, String? arabicFormat, PaginatorKeyMap? keyMap}) → PaginatorModel
Creates a copy with the given fields replaced.
getSliceBounds(int length) → (int, int)
Returns the slice bounds for the current page.
goToPage(int p) → PaginatorModel
Navigates to a specific page.
init() → Cmd?
Returns an optional command to execute on program startup.
override
itemsOnPage(int totalItems) → int
Returns the number of items on the current page.
nextPage() → PaginatorModel
Navigates to the next page.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prevPage() → PaginatorModel
Navigates to the previous page.
setTotalPages(int items) → PaginatorModel
Calculates the total number of pages from the given item count.
toString() → String
A string representation of this object.
inherited
update(Msg msg) → (PaginatorModel, Cmd?)
Updates the component state in response to a message.
override
view() → String
Renders the current model state for display.
override

Operators

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