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

Time:12-18

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'));

CodePudding user response:

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);
  • Related