recalculateDynamicRoutes method

void recalculateDynamicRoutes({
  1. bool shouldNotify = true,
})

Implementation

void recalculateDynamicRoutes({bool shouldNotify = true}) {
  final dynRoutes = routeInfos.whereType<DynamicRouteInfo>();

  bool notifiy = false;

  for (final dynRoute in dynRoutes) {
    final result = dynRoute.when(nomoNavigatorKey.currentContext!);
    final previousResult = _dynRouteStates[dynRoute];

    if (result == previousResult) continue;

    _dynRouteStates[dynRoute] = result;

    final page = _stack.singleWhereOrNull(
      (page) => page.routeInfo == dynRoute,
    );
    if (page == null) continue;

    final copy = page.copy;
    _stack[_stack.indexOf(page)] = copy;

    if (page.page.key is GlobalKey) {
      _pagesKeys[page.page.key as GlobalKey] = copy.key!;
    }

    notifiy = true;
  }

  if (notifiy && shouldNotify) {
    notifyListeners();
  }
}