popFor<T> method

  1. @override
void popFor<T>(
  1. BuildContext context,
  2. int numberOfPagesToPop, {
  3. required Widget currentPage,
  4. T? popResult,
})
override

You can reset the flow, eg. go back to the first Participator page, or the Initiator page with popFor.

popFor guarantees that you will never pop beyond the Initiator page.

// Pop just 2 pages while returning true as the result to those two pages.
dynamicRoutesNavigator.popFor(context, 2, true);

// This pops until the first participator page.
final currentPageIndex = dynamicRoutesNavigator.getCurrentPageIndex();
dynamicRoutesNavigator.popFor(context, currentPageIndex);

// Add + 1 to currentPageIndex or just use double.infinity to pop to the Initiator page.
dynamicRoutesNavigator.popFor(context, currentPageIndex);
dynamicRoutesNavigator.popFor(context, double.infinity);

Implementation

@override
void popFor<T>(BuildContext context, int numberOfPagesToPop,
    {required Widget currentPage, T? popResult}) async {
  if (numberOfPagesToPop == 0) return;

  assert(
      _widget != null,
      "pushFirst() "
      "of the dynamicRoutesInitiator instance should be called before calling "
      "this method on a participator");

  final _currentPage = _getCurrentPageDLLData(currentPage);

  final currentPageIndex =
      _currentPage.getTraversalSteps(PageDLLTraversalDirection.left);
  // + 1 because we allow the first participator page to be popped as well.
  final poppablePages = currentPageIndex + 1;
  final loopCount = min(numberOfPagesToPop, poppablePages);
  for (int i = 0; i < loopCount; i++) {
    popCurrent(context, currentPage: _widget!, popResult: popResult);
  }
}