dvHomeWidgetRouteForLink function

String? dvHomeWidgetRouteForLink(
  1. String link
)

The route link asks for when it is a home widget's tap, else null.

The inverse of dvHomeWidgetLaunchUrl, and the half that did not exist. Both platforms launched the application at a URL naming the widget's route, and the general rule for a dartvel:// link folds the host back into the path -- so dartvel://widget/widgets/order-status came out as /widget/widgets/order-status, which no router has. A widget on somebody's home screen opened the not-found page, and nothing at either end had anything to report.

Null for everything that is not this exact shape. Claiming a link that merely carries the host would send a half-written URL to /widgets/, which matches no widget and reads as one that was removed.

Implementation

String? dvHomeWidgetRouteForLink(String link) {
  final Uri? uri = Uri.tryParse(link.trim());
  if (uri == null || !uri.hasScheme) return null;
  if (uri.host != dvHomeWidgetLaunchHost) return null;
  final List<String> segments = uri.pathSegments;
  if (segments.length != 2 || segments[0] != 'widgets') return null;
  final String id = segments[1];
  if (id.isEmpty) return null;
  // Through the same function the build wrote the route with, rather than
  // rebuilt from the pieces here. That is what keeps the two ends from
  // drifting when the route shape changes.
  return dvHomeWidgetRoute(id);
}