infinite_scroll_pagination
infinite_scroll_pagination copied to clipboard
can I use the same PaginatedListView to show result from different API?
first of all, I wanna say thank you very much for making this amazing package, it really helps my app development.
I have a page/screen that has a list with a search bar like this: https://i.stack.imgur.com/ZLPtj.png
I can get the invoice list using the code below
final PagingController<int, Invoice> _pagingController =
PagingController(firstPageKey: 0);
@override
void initState() {
_pagingController.addPageRequestListener((pageKey) {
_fetchPage(pageKey);
});
super.initState();
}
Future<void> _fetchPage(int pageKey) async {
try {
final newItems = await RemoteApi.getInvoiceList(pageKey, _pageSize);
final isLastPage = newItems.length < _pageSize;
if (isLastPage) {
_pagingController.appendLastPage(newItems);
} else {
final nextPageKey = pageKey + newItems.length;
_pagingController.appendPage(newItems, nextPageKey);
}
} catch (error) {
_pagingController.error = error;
}
}
now I need to implement searching using a bar, to search a single Invoice object from server. but unfortunately, the API to get the invoice list and to get a single invoice is different.
let say to get invoice list, I use this endpoint
http://www.myapi.com/invoice/list
and to get single invoice, I use this endpoint
http://www.myapi.com/invoice/invoiceCodeHere
can I use the same PaginatedListView from this package to show a single invoice from different API? how to do that ?
I am trying to use the code below, it works actually, but it will not show the circular loading indicator on the center when loading data for the first time
final invoice = await invoiceAPI.getSingleInvoice(invoiceCode);
pagingController.itemList = [invoice];
pagingController.notifyListeners();