Skip to main content

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​

  1. Configure ChottuLink Dashboard
    • Set up your project
    • Configure Android Or iOS app settings respectively
    • Get your API key
  2. Install ChottuLink Flutter SDK
  3. 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

});
note

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.

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}");
});

URL Processing

Advancedv1.0.9+

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

New Feature

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

ParameterTypeRequiredDescription
shortUrlString

Yes

The shortened URL string to be resolved
onSuccessFunction(ResolvedLink resolvedLink)NoCalled on successful link resolve
onErrorFunction(ChottuLinkError error)NoCalled 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