> ## Documentation Index
> Fetch the complete documentation index at: https://docs.law4devs.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# Pagination

> Understand manual and automatic pagination in the Flutter SDK.

## Overview

Every `list()` call returns a `Page<T>`. The `iter()` method returns a `Stream<T>` that lazily auto-paginates across all pages.

***

## The `Page<T>` Object

```dart theme={null}
final page = await client.frameworks.list(page: 1, perPage: 20);

page.data          // List<T> — items on this page
page.meta.total    // int — total items across all pages
page.meta.page     // int — current page number
page.meta.perPage  // int — items per page
page.meta.pages    // int — total number of pages
page.links.next    // String? — URL of next page (null if last page)
page.links.prev    // String? — URL of previous page (null if first page)
page.hasNext       // bool — true if more pages exist
```

**`PageMeta` fields**

| Field        | Type     | Description        |
| ------------ | -------- | ------------------ |
| `apiVersion` | `String` | API version string |
| `total`      | `int`    | Total items        |
| `page`       | `int`    | Current page       |
| `perPage`    | `int`    | Items per page     |
| `pages`      | `int`    | Total pages        |

***

## Manual Pagination

```dart theme={null}
var page = 1;
while (true) {
  final result = await client.frameworks.list(page: page, perPage: 20);
  for (final fw in result.data) {
    print(fw.name);
  }
  if (!result.hasNext) break;
  page++;
}
```

***

## Automatic Pagination with `iter()`

`iter()` returns a `Stream<T>` — it fetches the next page only when the current page is exhausted:

```dart theme={null}
await for (final fw in client.frameworks.iter()) {
  print(fw.name);
}
```

With a custom page size:

```dart theme={null}
await for (final a in client.articles.iter('gdpr', perPage: 50)) {
  print(a.title);
}
```

***

## Early Stopping

```dart theme={null}
await for (final fw in client.frameworks.iter()) {
  if (fw.slug == 'gdpr') {
    print('Found GDPR');
    break;
  }
}
```

***

## Progress Tracking

```dart theme={null}
var count = 0;
final total = (await client.frameworks.list()).meta.total;

await for (final fw in client.frameworks.iter()) {
  count++;
  print('[$count/$total] ${fw.name}');
}
```
