flutterdart

How to load next page using youtube_explode_dart in flutter


How can I load the next video batch after displaying the first 20 videos by youtube_explode_dart?

my package version

youtube_explode_dart: ^2.0.2

Future<void> getData() async {
isLoading = true;
String query;

if (searchQueryController.text.trim().isEmpty) {
  query = 'trending hindi punjabi english and bhojpuri songs';
} else {
  query = searchQueryController.text.trim();
}

data = await yt.search.search(query, filter: SortFilters.relevance);

await data!.nextPage();

setState(() {
  searchQueryList = data!.toList();
});

isLoading = false;

}

this is the code I am using to fetch the first 20 videos and there is also data!.nextPage() to fetch the next batch but it is not working and just refreshing the same page.


Solution

  • You were not using the data that was return from data!.nextPage();

    final nextPageData = await data!.nextPage(); // check here
    
        setState(() {
    
      //    if you want to add to your initial data
      //    searchQueryList = [...data!.toList(), ...nextPageData?.toList()];
    
      //    if you want replace initial data
            searchQueryList = (nextPageData??[]).toList();
        });