First of all, appreciate for a great work. However I encountered a problem.
When the fetched data length from backend is less than the page size, for example data length for page 1 is 5 and page size is 25,
Widget loads the same page again.
Here is the code block I used for achieving the pagination.
body: SafeArea(
child: PaginationView<Purchase>(
paginationViewType: PaginationViewType.listView,
itemBuilder: (BuildContext context, Purchase history, int index) => listItem(context, history, index),
pageFetch: fetchSearchHistory,
shrinkWrap: true,
pullToRefresh: true,
onError: (dynamic error) => Container(
height: 70,
alignment: Alignment.center,
child: Text('Some error occured.', style: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.w400,
)),
),
onEmpty: Container(
height: 70,
alignment: Alignment.center,
child: Text('No past searches', style: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.w400,
)),
),
bottomLoader: Center(
child: CircularProgressIndicator(),
),
initialLoader: Container(
height: 70,
alignment: Alignment.center,
child: CircularProgressIndicator(),
),
),
)
Future<List<Purchase>> fetchSearchHistory(offset) async {
var page = (offset / 25).round() + 1;
print(page);
try {
return await ApiServices.purchaseHistory(page);
} catch (error) {
print(error);
return [];
}
}
First of all, appreciate for a great work. However I encountered a problem.
When the fetched data length from backend is less than the page size, for example data length for page 1 is 5 and page size is 25,
Widget loads the same page again.
Here is the code block I used for achieving the pagination.
And the page pageFetch method is: