deepLinkService constant
String
const deepLinkService
Implementation
static const String deepLinkService = '''import 'dart:async';
import 'package:flutter/services.dart';
/// Service that coordinates platform-level deep link retrieval and stream.
class DeepLinkService {
static const MethodChannel _channel = MethodChannel('{{CHANNEL}}');
final StreamController<String> _linkStreamController = StreamController<String>.broadcast();
DeepLinkService() {
_channel.setMethodCallHandler((MethodCall call) async {
if (call.method == 'onLink') {
final String? link = call.arguments as String?;
if (link != null) {
_linkStreamController.add(link);
}
}
});
}
/// Returns the stream of incoming deep links.
Stream<String> get linkStream => _linkStreamController.stream;
/// Retrieves the initial deep link that opened the app, if any.
Future<String?> getInitialLink() async {
try {
return await _channel.invokeMethod<String>('getInitialLink');
} on PlatformException catch (_) {
return null;
}
}
/// Closes the stream controller resources.
void dispose() {
_linkStreamController.close();
}
}
''';