buildState method

  1. @visibleForTesting
GoRouterState buildState(
  1. RouteMatchList matchList,
  2. RouteMatch match
)

Helper method that builds a GoRouterState object for the given match and pathParameters.

Implementation

@visibleForTesting
GoRouterState buildState(RouteMatchList matchList, RouteMatch match) {
  final RouteBase route = match.route;
  String? name;
  String path = '';
  if (route is GoRoute) {
    name = route.name;
    path = route.path;
  }
  final RouteMatchList effectiveMatchList;
  if (match is ImperativeRouteMatch) {
    effectiveMatchList = match.matches;
    if (effectiveMatchList.isError) {
      return _buildErrorState(effectiveMatchList);
    }
  } else {
    effectiveMatchList = matchList;
    assert(!effectiveMatchList.isError);
  }
  return GoRouterState(
    configuration,
    uri: effectiveMatchList.uri,
    matchedLocation: match.matchedLocation,
    name: name,
    path: path,
    fullPath: effectiveMatchList.fullPath,
    pathParameters:
        Map<String, String>.from(effectiveMatchList.pathParameters),
    error: effectiveMatchList.error,
    extra: effectiveMatchList.extra,
    pageKey: match.pageKey,
  );
}