transformUri method

Future<Uri> transformUri(
  1. Uri uri
)

Transforms a ULink URI into a route-compatible URI.

This method processes ULink URIs and attempts to resolve them to appropriate route paths using the provided routeResolver.

Returns the transformed URI or the original URI if no transformation is possible or needed.

Implementation

Future<Uri> transformUri(Uri uri) async {
  try {
    _log('Transforming URI: $uri');

    // Check if this is a ULink URI that needs processing
    if (!_isULinkUri(uri)) {
      _log('URI is not a ULink URI, returning as-is');
      return uri;
    }

    // Resolve the ULink
    final resolvedData = await _resolveULink(uri);
    if (resolvedData == null) {
      _log('Failed to resolve ULink, returning original URI');
      return uri;
    }

    // Handle unified links
    if (resolvedData.linkType == ULinkType.unified) {
      return _handleUnifiedLink(resolvedData, uri);
    }

    // Use custom route resolver if provided
    if (routeResolver != null) {
      final routePath = routeResolver!(resolvedData);
      if (routePath != null) {
        _log('Custom resolver returned route: $routePath');
        return Uri.parse(routePath);
      }
    }

    // Fallback to default behavior
    return _getDefaultRoute(resolvedData, uri);
  } catch (e) {
    _log('Error transforming URI: $e');
    return uri;
  }
}