fromRouteInformation static method

RouteData fromRouteInformation(
  1. RouteInformation routeInfo
)

Creates a RouteData from a RouteInformation.

The RouteInformation will usually be provided by the system.

Implementation

static RouteData fromRouteInformation(RouteInformation routeInfo) {
  final state = routeInfo.state;
  if (state is Map) {
    final requestSource = state['requestSource'] as String;

    return RouteData(
      state['internalPath'] as String,
      isReplacement: state['isReplacement'] as bool,
      requestSource: RequestSource.values.firstWhere(
        (source) => source.toString() == requestSource,
      ),
      pathTemplate: state['pathTemplate'] as String,
      pathParameters: (state['pathParameters'] as Map<String, dynamic>)
          .cast<String, String>(),
      historyIndex: state['historyIndex'] as int?,
    );
  }

  // No state: we only got a URL from the system, so probably a
  // manually-entered URL from the user.
  return RouteData(
    routeInfo.location!,
    pathTemplate: routeInfo.location!,
    requestSource: RequestSource.system,
  );
}