setNewRoutePath method

  1. @override
Future<void> setNewRoutePath(
  1. RouterConfiguration configuration
)
override

Called by the Router when the Router.routeInformationProvider reports that a new route has been pushed to the application by the operating system.

Consider using a SynchronousFuture if the result can be computed synchronously, so that the Router does not need to wait for the next microtask to schedule a build.

Implementation

@override
Future<void> setNewRoutePath(RouterConfiguration configuration) async {
  var newStack = <NomoPage>[];

  bool containtsNestedRouterPage(List<NomoPage> stack) {
    return stack.whereType<NestedNavigatorPage>().isNotEmpty;
  }

  for (final routeSettings in configuration) {
    final routeInfo = routeInfos.singleWhereOrNull(
      (element) => element.path == routeSettings.name,
    );

    if (routeInfo == null) {
      continue;
    }

    final isInital = routeInfo == initialRouteInfo;

    final page = isInital
        ? initial!
        : appRouter.getRouteForPath(routeInfo.path)().page;

    final nestedNav = isNestedRoute(routeInfo);

    if (nestedNav != null && !containtsNestedRouterPage(newStack)) {
      newStack.add(_getNestedRouterPage(nestedNav));
      newStack.add(_nestedPageFromRouteInfo(routeInfo, page));
      continue;
    }

    newStack.add(
      switch (nestedNav != null) {
        true => _nestedPageFromRouteInfo(
            routeInfo,
            page,
            urlArguments: routeSettings.arguments as JsonMap?,
          ),
        false => _pageFromRouteInfo(
            routeInfo,
            page,
            urlArguments: routeSettings.arguments as JsonMap?,
          ),
      },
    );
  }

  if (newStack.isEmpty) {
    return;
  }

  _stack = newStack;

  notifyListeners();

  return SynchronousFuture(null);
}