dvAndroidLaunchRoute function

String? dvAndroidLaunchRoute(
  1. String? uri
)

The route an application was launched at, from the URI it was given.

A home widget's tap is a deep link to the route Dartvel generated for it, which is the whole of "home widgets can launch and navigate to pages within the app" on Android. App links arrive the same way, so this reads the path out of whatever scheme it was given rather than only the widget one.

Null for a launch with no link. Answering / would make every cold start look like a deep link to the home page, and the caller has to be able to tell those apart.

Implementation

String? dvAndroidLaunchRoute(String? uri) {
  if (uri == null || uri.isEmpty) return null;
  final Uri? parsed = Uri.tryParse(uri);
  if (parsed == null || parsed.path.isEmpty) return null;
  // A path that is not a path is not a route. `Uri.tryParse` accepts a good
  // deal that is not an address, and a route built out of it would be a
  // not-found page on launch.
  if (!parsed.path.startsWith('/')) return null;
  return parsed.hasQuery ? '${parsed.path}?${parsed.query}' : parsed.path;
}