deepLinkManager constant

String const deepLinkManager

Implementation

static const String deepLinkManager = '''import 'dart:async';
import 'deep_link_service.dart';
import 'deep_link_parser.dart';
import 'deep_link_route.dart';
import 'deep_link_routes.dart';

/// Coordinates deep link handling and dispatches matched routes to the application.
class DeepLinkManager {
final DeepLinkService _service;
StreamSubscription<String>? _subscription;
String? _currentLink;

DeepLinkManager({DeepLinkService? service}) : _service = service ?? DeepLinkService();

String? get currentLink => _currentLink;

/// Starts listening to deep link changes.
void initialize() {
  // Check initial link
  _service.getInitialLink().then((link) {
    if (link != null) {
      handleLink(link);
    }
  });

  // Listen to incoming links
  _subscription = _service.linkStream.listen((link) {
    handleLink(link);
  });
}

/// Standard handler to process a link.
void handleLink(String url) {
  _currentLink = url;
  final route = DeepLinkParser.parse(url);
  if (route != null) {
    DeepLinkRoutes.dispatch(route);
  }
}

/// Disposes of active resources.
void dispose() {
  _subscription?.cancel();
  _service.dispose();
}
}
''';