'can I use the same paginated list view to show result from different API?

I am using infinite_scroll_pagination package. and I have a page that has a list with a search bar like this

enter image description here

I can get the 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.

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 infinite_scroll_pagination 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();


Solution 1:[1]

final invoiceData = await invoiceAPI.getSingleInvoice(invoiceCode);

pagingController.itemList = [invoiceData]; pagingController.notifyListeners();

pagingController.refresh();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 blackwolf