How to append data into a Future<List<Adds>>

I want to create a on scroll data load. currently I am getting data(ad list) from a api call as a Future<List<Ads>>

in scroll listener function I just want to append next page data list.

there was a example of doing it with a list, I just want to do the same with a Future list

items.addAll(List.generate(42, (index) => 'Inserted $index'));

Upvotes: 1

Views: 2038

Answers (1)

Stefan Galler
Stefan Galler

Reputation: 831

You could simply do this:

Future<List<Ads>> appendElements(Future<List<Ads>> listFuture, List<Ads> elementsToAdd) async {
  final list = await listFuture;
  list.addAll(elementsToAdd);
  return list;
}

And then call it like this:

appendedListFuture = appendElements(items, yourItemsToAdd);

Upvotes: 1

Related Questions