parseRouteInformation method

  1. @override
Future<AppScreenRoutePath> parseRouteInformation(
  1. RouteInformation route_information
)
override

Converts the given route information into parsed data to pass to a RouterDelegate.

The method should return a future which completes when the parsing is complete. The parsing may be asynchronous if, e.g., the parser needs to communicate with the OEM thread to obtain additional data about the route.

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 pass the data to the RouterDelegate.

One can implement parseRouteInformationWithDependencies instead if the parsing depends on other dependencies from the BuildContext.

Implementation

@override
Future<AppScreenRoutePath> parseRouteInformation(
    RouteInformation route_information) async {
  final uri = Uri.parse(route_information.location!);
  // Handle '/'
  if (uri.pathSegments.length == 0) {
    return AppScreenRoutePath.home();
  }

  print("Complete URL: $uri");

  if (uri.pathSegments.length >= 1) {
    var name = uri.path.substring(1, uri.path.length);

    AppScreen app_screen = app_screens.singleWhere(
        (current_app_screen) => current_app_screen.name == name, orElse: () {
      return AppScreen(
        name: "",
        child: Container(),
      );
    });

    app_screen.app_path = uri.toString();

    if (app_screen.name == "") {
      return AppScreenRoutePath.unknown();
    } else {
      return AppScreenRoutePath.details(name);
    }
  }

  // Handle unknown routes
  return AppScreenRoutePath.unknown();
}