deepLinkParser constant
String
const deepLinkParser
Implementation
static const String deepLinkParser = '''import 'deep_link_route.dart';
import 'deep_link_constants.dart';
/// Parses raw deep link URLs into structured [DeepLinkRoute] configurations.
class DeepLinkParser {
/// Parses the raw URL string. Returns null if invalid or doesn't match scheme.
static DeepLinkRoute? parse(String urlString) {
try {
final uri = Uri.parse(urlString);
// Validate scheme
final allowedSchemes = DeepLinkConstants.allowedSchemes;
if (!allowedSchemes.contains(uri.scheme.toLowerCase()) &&
uri.scheme != 'http' &&
uri.scheme != 'https') {
return null;
}
final List<String> segments = uri.pathSegments.where((s) => s.isNotEmpty).toList();
String screen = '';
if (uri.host.isNotEmpty && uri.scheme != 'http' && uri.scheme != 'https') {
// custom scheme myapp://screen/path
screen = uri.host;
segments.insert(0, uri.host);
} else if (segments.isNotEmpty) {
// http(s) link e.g. https://domain.com/screen/path
screen = segments.first;
}
return DeepLinkRoute(
screen: screen,
pathSegments: segments,
queryParameters: uri.queryParameters,
);
} catch (_) {
return null;
}
}
}
''';