Handle Dynamic Links in Flutter
Enable your Flutter app to receive and handle ChottuLinks seamlessly. This allows users to open specific screens when they tap a dynamic link, whether the app is running, in the background, or launched from a cold start. Integrate link handling to ensure a smooth and context-aware user experience across platforms.
Prerequisites
- Configure ChottuLink Dashboard
- Set up your project
- Configure Android Or iOS app settings respectively
- Get your API key
- Install ChottuLink Flutter SDK
- Initialize ChottuLink Flutter SDK
Implementation Guide
Tip: You should call this inside the first screen that your app naturally opens (typically right after the splash screen).
/// ✅ Import ChottuLink SDK packages
import 'package:flutter/material.dart';
import 'package:chottu_link/chottu_link.dart';
/// 🔗 Listen for incoming dynamic links
ChottuLink.onLinkReceived.listen((String link) {
debugPrint(" ✅ Link Received: $link");
/// Tip: ➡️ Navigate to a specific page or take action based on the link
});
If you set allowedDomains in ChottuLink.init(), only links whose host matches the list are delivered here. Other links are left to your app's own deep link handling. See Restricting which links ChottuLink handles.
(Optional) Listen for Incoming Dynamic Links (with Metadata)
You can listen for incoming dynamic links — including deferred links — along with their associated metadata using the onLinkReceivedWithMeta stream, which is available from v1.0.17.
Tip: You should call this inside the first screen that your app naturally opens (typically right after the splash screen).
/// ✅ Import ChottuLink SDK packages
import 'package:flutter/material.dart';
import 'package:chottu_link/chottu_link.dart';
/// 🔗 Listen for incoming dynamic links with metadata
ChottuLink.onLinkReceivedWithMeta.listen((resolvedLink) {
debugPrint("✅ Resolved Link: ${resolvedLink.link}");
debugPrint("🔗 Short Link: ${resolvedLink.shortLink}");
debugPrint("📎 Raw Short Link: ${resolvedLink.shortLinkRaw}");
debugPrint("✅ Is Deferred Link: ${resolvedLink.isDeferred}");
});
(Optional) Get AppLink Data from the Deeplink URL directly
URL Processing
Process the shortened Deeplink using the getAppLinkDataFromUrl method.
This retrieves the associated app link data and returns a ResolvedLink object containing the resolved destination URL and the original short link.
Method Signature
This method was introduced in SDK version v1.0.9+
static Future<void> getAppLinkDataFromUrl({
required String shortUrl,
void Function(ResolvedLink resolvedLink)? onSuccess,
void Function(ChottuLinkError error)? onError,
});
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
shortUrl | String | Yes | The shortened URL string to be resolved |
onSuccess | Function(ResolvedLink resolvedLink) | No | Called on successful link resolve |
onError | Function(ChottuLinkError error) | No | Called if link resolve fails |
Return Value
A ResolvedLink object containing:
class ResolvedLink {
String? link;
String? shortLink;
ResolvedLink({this.link, this.shortLink});
}
Basic Implementation
ChottuLink.getAppLinkDataFromUrl(
shortUrl: "https://yourApp.chottu.link/xxxxxx",
onSuccess: (resolvedLink) {
print("✅ Link: ${resolvedLink.link}");
print("✅ Short Link: ${resolvedLink.shortLink}");
},
onError: (error) {
print("❌ Error: ${error.message}");
},
);
Use Cases
- Manual Link Processing: Process links from user input
- Testing: Test deep link functionality
- Background Processing: Process links in background tasks
- Link Validation: Validate links before processing