onDeepLink method

void onDeepLink(
  1. DeepLinkCallback callback
)

Registers a callback for direct deep links

  • callback: Callback to invoke when app is opened via deep link

If a link was handled before any callback was registered (typically the link that launched the app), it is delivered in a microtask to every callback registered by then, once.

Implementation

void onDeepLink(DeepLinkCallback callback) {
  final pending = _pendingDeepLink;
  final isFirstCallback = _deepLinkCallbacks.isEmpty;
  _deepLinkCallbacks.add(callback);

  if (pending != null && isFirstCallback) {
    Future.microtask(() {
      if (!identical(_pendingDeepLink, pending)) return;
      _pendingDeepLink = null;
      final callbacks = List<DeepLinkCallback>.from(_deepLinkCallbacks);
      for (final cb in callbacks) {
        cb(pending.uri, pending.data);
      }
    });
  }
}