chunk 1.0.0 copy "chunk: ^1.0.0" to clipboard
chunk: ^1.0.0 copied to clipboard

A package used to agnostically chunk and paginate your data

Used to paginate any type of data

Getting started #

Simply use the Chunker class to select the value you'll be using as your identifier between chunks. Then supply a function to be called each time you need a new chunk from your data source. Once those are provided, a single function is all that's needed to infinitely walk through your data.

Usage #

Set up #

final chunker = Chunker<String, String>(
  cursorSelector: (v) => v,
  dataChunker: (cursor, limit) {
  final isFirstRun = cursor == null;

  return isFirstRun
    ? dataSource.take(limit)
    : dataSource
      .skipWhile((value) => value != cursor)
      .skip(1) // Start after the previous cursor
      .take(limit);
  },
);

Paginate #

First Chunk

For the first chunk you can provide a new Chunk with a custom limit or provide null to accept the default limit of 20

final Chunk<String, String> nextChunk = await chunker.getNext(
  Chunk(limit: 15),
);

Remaining Chunks

For all future chunks, all you need to do is pass the previous chunk in.

await chunker.getNext(nextChunk);
2
likes
0
pub points
50%
popularity

Publisher

unverified uploader

A package used to agnostically chunk and paginate your data

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

equatable

More

Packages that depend on chunk