toOriginUrl method
Restores the original URL from a local URL.
- If the 'origin' query parameter exists, decodes it and uses it as the base.
- Replaces the path and query parameters with those from the current URL, except for the 'origin' parameter which is removed.
- If 'origin' is missing, returns itself.
Implementation
String toOriginUrl() {
Uri uri = this.toSafeUri();
Map<String, String> queryParameters = {...uri.queryParameters};
if (!queryParameters.containsKey('origin')) return this;
String? origin = queryParameters['origin'];
if (origin != null && origin.isNotEmpty) {
origin = utf8.decode(base64Url.decode(origin));
}
if (origin == null) return this;
Uri originUri = Uri.parse(origin);
queryParameters.remove('origin');
originUri = originUri.replace(
path: uri.path,
queryParameters: queryParameters.isNotEmpty ? queryParameters : null,
);
return originUri.toString();
}