Skip to main content

sinew_paging 1.1.0 copy "sinew_paging: ^1.1.0" to clipboard
sinew_paging: ^1.1.0 copied to clipboard

Pager, PagingState and LoadType: the paging rules in one place.

sinew_paging #

pub package License Docs

Pager, PagingState and LoadType: the paging rules in one place.

A list needs the same rules in every screen: load the first page once per query, load more only when there is a next page, retry the load that failed, and let a refresh replace what is running. Pager holds those rules, and holds no UI state: it reads the current state and writes the next one.

Features #

  • Four strategies for four backends: Pager.offset, Pager.offsetByTotal, Pager.cursor and Pager.lastItem
  • PagingState with canLoadMore and retryType, so the UI never decides "may I load more" itself
  • LoadType (initial, refresh, more) stays set after a load, so the UI can tell a first-page failure from a next-page failure
  • Stale loads are dropped: a newer load, or a refresh, supersedes whatever is running

Getting started #

dart pub add sinew_paging

Usage #

final pager = Pager<Order>.offset(
  (page, query) => repository.orders(page),
  itemKey: (order) => order.id,
);
var state = const PagingState<Order>();

await pager.load(LoadType.initial, state, update: (next) => state = next);
while (state.canLoadMore) {
  await pager.load(LoadType.more, state, update: (next) => state = next);
}

In a real page, update writes the state your notifier or view model owns. The full program is in example/main.dart.

Sinew is one architecture for Flutter and Kotlin, released as a set of packages at one version.

Documentation #

License #

Apache 2.0, see LICENSE.

0
likes
160
points
344
downloads

Documentation

Documentation
API reference

Publisher

verified publishersrctool.com

Weekly Downloads

Pager, PagingState and LoadType: the paging rules in one place.

Repository (GitHub)
View/report issues
Contributing

Topics

#pagination #paging #architecture #state-management

License

Apache-2.0 (license)

Dependencies

sinew_exception, sinew_models

More

Packages that depend on sinew_paging