Dynalinks
Flutter

SDK

The Dynalinks Flutter SDK provides deferred deep linking and Universal Link / App Link handling for your Flutter app. It wraps the native iOS and Android SDKs to provide a unified Dart API.

Features

  • Deferred Deep Linking: Route users to specific content even when installing the app for the first time
  • Universal Links / App Links: Handle incoming deep links automatically
  • Cross-Platform: Single API for both iOS and Android
  • Type-Safe: Full Dart type safety with comprehensive error handling

Requirements

  • Flutter 3.44 or later (Dart 3.12 or later)
  • iOS 16.0 or later
  • Android API 21 or later

On iOS the plugin builds with either Swift Package Manager (the default from Flutter 3.44) or CocoaPods. It ships a privacy manifest, so its data use is included in your app's privacy report automatically.

Upgrading from 1.x? See Upgrading from 1.x.

Installation

Add dynalinks to your pubspec.yaml:

dependencies:
  dynalinks: ^2.0.0

Then run:

flutter pub get

iOS Setup

  1. Register your iOS app in the Dynalinks Console:

    • Bundle Identifier (from Xcode project settings)
    • Team ID (from Apple Developer account)
    • App Store ID (from your app's App Store URL)
  2. Configure Associated Domains in Xcode:

    • Open your iOS project > Signing & Capabilities
    • Add the "Associated Domains" capability
    • Add your domain: applinks:yourproject.dynalinks.app
  3. Set the iOS deployment target to 16.0:

    • Open ios/Runner.xcworkspace, select the Runner target, and go to General > Minimum Deployments
    • Set iOS to 16.0 or later
    • If your project uses CocoaPods, also set platform :ios, '16.0' in ios/Podfile

    Flutter's default is lower, so a project created from the Flutter template fails to build until you raise it. See Build fails with a minimum platform version error.

See the iOS integration guide for detailed instructions.

UIScene life cycle

The plugin receives links through both the app delegate and the scene delegate, so it works whichever life cycle your app uses. If your app has not adopted the UIScene life cycle yet, flutter run migrates it for you.

Under UIScene, a link that launches the app is delivered while the scene connects, so plugins must be registered by then. The automatic migration takes care of this. If you maintain ios/Runner/AppDelegate.swift by hand, register plugins in didInitializeImplicitFlutterEngine, not in didFinishLaunchingWithOptions:

@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
  func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
    GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
  }
}

If you register plugins later, the plugin is not listening yet when the launch link arrives, and cold-start links are missed.

Android Setup

  1. Register your Android app in the Dynalinks Console:

    • Package identifier (from build.gradle applicationId)
    • SHA-256 certificate fingerprint (run ./gradlew signingReport)
  2. Add the JitPack repository to android/build.gradle.kts, where the Flutter template declares its repositories:

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://jitpack.io") }
    }
}

If your project declares repositories in a dependencyResolutionManagement block in android/settings.gradle.kts instead, add it there.

  1. Add an intent filter to your existing MainActivity in android/app/src/main/AndroidManifest.xml. Leave the rest of the activity as Flutter generated it. You do not need to change launchMode.
<activity android:name=".MainActivity">

    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:scheme="https"
            android:host="yourproject.dynalinks.app" />
    </intent-filter>
</activity>

See the Android integration guide for detailed instructions.

Note

The plugin uses Flutter's built-in Kotlin support and builds under AGP 9. It compiles against Java 17, so if your app pins an older JVM target you may need to raise it.

Setup

Configure the SDK

Initialize the SDK as early as possible in your app's lifecycle:

import 'package:flutter/material.dart';
import 'package:dynalinks/dynalinks.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Dynalinks.configure(
    clientAPIKey: 'your-client-api-key',
    logLevel: DynalinksLogLevel.debug, // Use .error in production
  );

  runApp(const MyApp());
}

Get your Client API Key from the Dynalinks Console by navigating to your project's Settings → Mobile SDK.

Configuration Options

await Dynalinks.configure(
  // Required: Your client API key from the Dynalinks console
  clientAPIKey: 'your-api-key',

  // Custom API URL (optional, defaults to production)
  baseURL: 'https://custom.api.url',

  // Log level (optional)
  // DynalinksLogLevel.none    - No logging
  // DynalinksLogLevel.error   - Errors only (default)
  // DynalinksLogLevel.warning - Warnings and errors
  // DynalinksLogLevel.info    - Info, warnings, and errors
  // DynalinksLogLevel.debug   - All logs
  logLevel: DynalinksLogLevel.debug,

  // Allow checks on simulator/emulator (optional, defaults to false)
  // Useful for development/testing
  allowSimulatorOrEmulator: false,
);

Usage

Check for deferred deep links on first launch:

Future<void> checkDeferredDeepLink() async {
  try {
    final result = await Dynalinks.checkForDeferredDeepLink();

    if (result.matched && result.link != null) {
      // User came from a deep link - navigate accordingly
      final deepLinkValue = result.link!.deepLinkValue;
      if (deepLinkValue != null) {
        navigateTo(deepLinkValue);
      }
    }
  } on SimulatorException {
    // Running on simulator - deferred deep linking not available
  } on DynalinksException catch (e) {
    print('Error: ${e.message}');
  }
}

Incoming links reach your app through two separate channels, and you need both:

  • getInitialLink(): the link that launched the app from a terminated state (cold start).
  • onDeepLinkReceived: links that arrive while the app is already running (warm start).

A launch link is delivered only through getInitialLink(), even if a stream listener is already attached. This keeps a single tap from being delivered twice, but it also means an app that only subscribes to the stream never sees cold-start links.

A link that arrives while no listener is attached is held and delivered to the next listener, so a tap during a route change is not lost. The SDK keeps the 32 most recent queued links and drops the oldest when that limit is reached.

getInitialLink() answers once. If it has already returned null, a launch link that resolves afterwards (after a very slow first request, or a failed configure() that you retried) arrives on the stream instead. Handling both channels, as below, covers this.

class _MyAppState extends State<MyApp> {
  StreamSubscription<DeepLinkResult>? _subscription;

  @override
  void initState() {
    super.initState();
    _checkInitialLink();
    _listenForLinks();
  }

  @override
  void dispose() {
    _subscription?.cancel();
    super.dispose();
  }

  Future<void> _checkInitialLink() async {
    // Check for cold start link
    final initialLink = await Dynalinks.getInitialLink();
    if (initialLink != null && initialLink.matched) {
      _handleResult(initialLink);
    }
  }

  void _listenForLinks() {
    _subscription = Dynalinks.onDeepLinkReceived.listen(_handleResult);
  }

  void _handleResult(DeepLinkResult result) {
    if (result.matched && result.link?.deepLinkValue != null) {
      // Navigate to the deep link destination
      Navigator.pushNamed(context, result.link!.deepLinkValue!);
    }
  }
}

Manually resolve a URI if needed:

final result = await Dynalinks.handleDeepLink(
  Uri.parse('https://yourproject.dynalinks.app/promo'),
);

if (result.matched) {
  // Handle the resolved link
}

DeepLinkResult

class DeepLinkResult {
  /// Whether a matching link was found
  final bool matched;

  /// Confidence level: high, medium, or low
  final Confidence? confidence;

  /// Match score (0-100)
  final int? matchScore;

  /// Link data if matched
  final LinkData? link;

  /// Whether this is from a deferred deep link
  final bool isDeferred;
}

class LinkData {
  final String id;                    // Unique link identifier
  final String? name;                 // Link name (for display)
  final String? path;                 // Link path
  final String? shortenedPath;        // Shortened path
  final Uri? url;                     // Original URL the link points to
  final Uri? fullUrl;                 // Full Dynalinks URL
  final String? deepLinkValue;        // Value for in-app navigation
  final bool? iosDeferredDeepLinkingEnabled;
  final Uri? iosFallbackUrl;          // iOS fallback URL
  final Uri? androidFallbackUrl;      // Android fallback URL
  final bool? enableForcedRedirect;
  final String? socialTitle;          // Social sharing title
  final String? socialDescription;    // Social sharing description
  final Uri? socialImageUrl;          // Social sharing image
  final int? clicks;                  // Number of clicks on this link
  final String? referrer;             // Referrer tracking parameter for attribution
  final String? providerToken;        // Apple Search Ads attribution token (pt)
  final String? campaignToken;        // Campaign identifier for attribution (ct)
}

Error Handling

The SDK uses typed exceptions for error handling:

try {
  final result = await Dynalinks.checkForDeferredDeepLink();
  // Handle result
} on NotConfiguredException {
  // SDK not configured - call configure() first
} on InvalidApiKeyException {
  // Invalid API key provided
} on SimulatorException {
  // Running on simulator/emulator (disabled by default)
} on NetworkException catch (e) {
  // Network request failed
  print('Network error: ${e.message}');
} on InvalidResponseException {
  // Server returned invalid response
} on ServerException catch (e) {
  // Server returned an error
  print('Server error: ${e.message}');
} on NoMatchException {
  // No matching link found
} on InvalidIntentException {
  // Invalid intent data (Android only)
} on InstallReferrerUnavailableException {
  // Install Referrer API unavailable (Android only)
} on InstallReferrerTimeoutException {
  // Install Referrer connection timed out (Android only)
} on UnknownException catch (e) {
  // Unknown error
  print('Unknown error: ${e.message}');
} on DynalinksException catch (e) {
  // Catch-all for other errors
  print('Error: ${e.message}');
}

API Reference

MethodDescription
configure()Initialize the SDK with your API key
checkForDeferredDeepLink()Check for deferred deep link (first launch)
handleDeepLink(Uri)Manually resolve a deep link URI
getInitialLink()Get the link that launched the app (cold start)
onDeepLinkReceivedStream of incoming links while app is running
reset()Reset SDK state. For tests only: it is annotated @visibleForTesting, so calling it from app code triggers an analyzer warning
versionSDK version string

Upgrading from 1.x

  1. Raise your minimum versions. 2.0.0 requires Flutter 3.44 and Dart 3.12.
  2. Call getInitialLink() on startup. A link that launched the app is now delivered only there, never on the onDeepLinkReceived stream. If your 1.x app relied on the stream alone, it silently stops receiving cold-start links. See Handle Incoming Deep Links.
  3. iOS: run the app once to migrate. flutter run adopts the UIScene life cycle and switches the project to Swift Package Manager for you. If you maintain AppDelegate.swift by hand, apply the plugin registration change shown in UIScene life cycle.
  4. iOS: update the native SDK. 2.0.0 requires Dynalinks iOS SDK 1.0.4 or later. With CocoaPods, run pod update DynalinksSDK in the ios directory. Swift Package Manager resolves it automatically.
  5. Android: you can drop launchMode="singleTask". Earlier versions of this guide asked for it, but deep linking does not need it. Keeping it is fine too.

Nothing changed in the Dart API: no method signatures, parameters or model fields were renamed or removed.

How It Works

  1. User clicks a Dynalinks link (app not installed)
  2. User is redirected to the app store
  3. User installs and opens the app
  4. App calls checkForDeferredDeepLink()
  5. SDK retrieves deferred link data using platform-specific methods:
    • iOS: Device fingerprint matching
    • Android: Google Play Install Referrer API
  6. Server returns original link data
  1. User clicks a Dynalinks link (app installed)
  2. Platform opens your app directly
  3. SDK receives the link via platform channel
  4. App receives it through getInitialLink() (cold start) or onDeepLinkReceived (warm start), never both

Platform-Specific Behavior

iOS

Uses the native iOS SDK with fingerprint matching. The SDK collects device information (screen size, OS version, timezone, IDFV) to match the user to their original link.

Android

Uses the Google Play Install Referrer API to reliably match the user to their original link based on the referrer URL passed from the Play Store.

More Information

On this page