Skip to content

Commit 106fca3

Browse files
committed
Pass the current list size into itemBuilder
1 parent 8110028 commit 106fca3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

example/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class _MyHomePageState extends State<MyHomePage> {
5252
return Scaffold(
5353
appBar: AppBar(title: Text(widget.title)),
5454
body: Pagination(
55-
pageBuilder: (currentListSize) => pageData(currentListSize),
56-
itemBuilder: (item) => ListTile(title: Text(item)),
55+
pageBuilder: (currentListSize) => pageData(currentSize),
56+
itemBuilder: (index, currentListSize, item) => ListTile(title: Text(item)),
5757
),
5858
);
5959
}

lib/paging.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:flutter/material.dart';
1111
typedef PaginationBuilder<T> = Future<List<T>> Function(int currentListSize);
1212

1313
/// Signature for a function that creates a widget for a given item of type 'T'.
14-
typedef ItemWidgetBuilder<T> = Widget Function(int index, T item);
14+
typedef ItemWidgetBuilder<T> = Widget Function(int index, int currentListSize, T item);
1515

1616
/// A scrollable list which implements pagination.
1717
///
@@ -129,7 +129,7 @@ class _PaginationState<T> extends State<Pagination<T>> {
129129
scrollDirection: widget.scrollDirection,
130130
itemBuilder: (context, position) {
131131
if (position < _list.length) {
132-
return widget.itemBuilder(position, _list[position]);
132+
return widget.itemBuilder(position, _list.length, _list[position]);
133133
} else if (position == _list.length && !_isEndOfList) {
134134
fetchMore();
135135
return widget.progress ?? defaultLoading();

0 commit comments

Comments
 (0)