dvStudioTargetFor function

DVStudioTarget? dvStudioTargetFor(
  1. String route, {
  2. required String mount,
})

The screen and object route under mount names, or null when it names neither -- a path nobody has, a file, an API call. Null rather than a guess, so a scanner walking the mount gets the application's own answer instead of a Studio page for every path it tries.

Implementation

DVStudioTarget? dvStudioTargetFor(String route, {required String mount}) {
  if (route == mount || route == '$mount/') {
    return DVStudioTarget(screen: dvStudioScreens.first);
  }
  final String prefix = '$mount/';
  if (!route.startsWith(prefix)) return null;
  final List<String> segments = <String>[
    for (final String raw in route.substring(prefix.length).split('/'))
      if (raw.isNotEmpty) Uri.decodeComponent(raw),
  ];
  if (segments.isEmpty) return null;
  final DVStudioScreenSpec? screen = dvStudioScreenFor(segments.first);
  if (screen == null) return null;
  return DVStudioTarget(screen: screen, object: segments.sublist(1));
}