locationOfAppSchemeUri function

String? locationOfAppSchemeUri(
  1. Uri uri,
  2. String scheme
)

The location an "Open in app" URL names: <scheme>:///product?id=42 is /product?id=42; <scheme>:////, <scheme>:/// and <scheme>:// are /. Null for any other URL, including one on another scheme or with a host.

Implementation

String? locationOfAppSchemeUri(Uri uri, String scheme) {
  if (scheme.isEmpty || uri.scheme != scheme.toLowerCase()) return null;
  if (uri.host.isNotEmpty || uri.userInfo.isNotEmpty || uri.hasPort) {
    return null;
  }
  final path = uri.path.replaceFirst(RegExp(r'^/+'), '/');
  return linkLocation(path.isEmpty ? '/' : path, uri.queryParameters);
}