canPop method

  1. @override
bool canPop({
  1. bool ignoreChildRoutes = false,
  2. bool ignoreParentRoutes = false,
  3. bool ignorePagelessRoutes = false,
})
override

Whether this controller can preform maybePop

if ignoreChildRoutes is true it will only check whether this controller has multiple entire and not care about pop-able child controllers

if ignoreParentRoutes is true it will only check whether this controller has multiple entire and not care about pop-able parent controllers

if ignorePagelessRoutes is true page-lss routes will not be considered in the calculation

Implementation

@override
bool canPop({
  bool ignoreChildRoutes = false,
  bool ignoreParentRoutes = false,
  bool ignorePagelessRoutes = false,
}) {
  if (_pages.length > 1 || (!ignorePagelessRoutes && hasPagelessTopRoute)) {
    return true;
  }

  if (!ignoreChildRoutes && _pages.isNotEmpty) {
    final innerRouter = _innerControllerOf(_pages.last.routeData.key);
    if (innerRouter != null &&
        innerRouter.canPop(
          ignoreParentRoutes: true,
          ignorePagelessRoutes: ignorePagelessRoutes,
        )) {
      return true;
    }
  }

  if (!ignoreParentRoutes && _parent != null) {
    return _parent!.canPop(
      ignorePagelessRoutes: ignorePagelessRoutes,
      ignoreChildRoutes: true,
    );
  }
  return false;
}