pushFor<T> method

  1. @override
List<Future<T?>> pushFor<T>(
  1. BuildContext context,
  2. int numberOfPagesToPush, {
  3. required Widget currentPage,
})
override

You can push multiple pages at once with pushFor.

This method guarantees that you will never push beyond the last Participator page.

// Pushes 4 pages.

dynamicRoutesParticipator.pushFor(context, 4);

// Pushes to the last participator page.
dynamicRoutesParticipator.pushFor(context, dynamicRoutesParticipator..getProgressFromCurrentPage());


// Pushes to the last participator page + invoke [lastPageCallback].
dynamicRoutesParticipator.pushFor(context, dynamicRoutesParticipator..getProgressFromCurrentPage() + 1);

Implementation

@override
List<Future<T?>> pushFor<T>(BuildContext context, int numberOfPagesToPush,
    {required Widget currentPage}) {
  assert(
      _widget != null,
      "pushFirst() "
      "of the dynamicRoutesInitiator instance should be called before calling "
      "this method on a participator");

  if (numberOfPagesToPush == 0) return [];

  final _currentPage = _getCurrentPageDLLData(currentPage);

  final pagesLeft =
      _currentPage.getTraversalSteps(PageDLLTraversalDirection.right);
  // + 1 because all pages length + lastPageCallback.
  final pushablePages = pagesLeft + 1;
  final loopCount = min(numberOfPagesToPush, pushablePages);

  final List<Future<T?>> results = [];
  for (int i = 0; i < loopCount; i++) {
    results.add(pushNext<T>(context, currentPage: _widget!));
  }

  return results;
}