flutter_deep_linker

Advanced deep linking with custom schemes and universal links for Flutter. Supports iOS, Android, Web, Windows, macOS, and Linux with WASM compatibility.

Pub Version Flutter Platform License

Features

  • 🌐 Multi-Platform Support: iOS, Android, Web, Windows, macOS, Linux
  • 🔗 Universal Links: iOS Universal Links and Android App Links
  • 🎯 Custom Schemes: Handle custom URL schemes (e.g., myapp://)
  • WASM Compatible: Full web platform support with WebAssembly
  • 🛡️ Security: Configurable URL validation and filtering
  • 📱 Cross-Platform: Consistent API across all platforms
  • 🚀 Performance: Optimized for high-performance deep linking

Getting Started

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_deep_linker: ^0.0.2

Basic Usage

import 'package:flutter_deep_linker/flutter_deep_linker.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // Initialize the deep linker
  final deepLinker = FlutterDeepLinker();
  await deepLinker.initialize();
  
  // Listen to deep link events
  deepLinker.linkStream.listen((result) {
    if (result.success) {
      print('Deep link received: ${result.url}');
      print('Scheme: ${result.scheme}');
      print('Host: ${result.host}');
      print('Path: ${result.path}');
      print('Query: ${result.queryParameters}');
    } else {
      print('Deep link error: ${result.error?.message}');
    }
  });
  
  runApp(MyApp());
}

Configuration

final config = DeepLinkConfig(
  schemes: ['https', 'http', 'myapp'],
  hosts: ['example.com', 'myapp.com'],
  allowCustomSchemes: true,
  allowUniversalLinks: true,
  allowAppLinks: true,
);

await deepLinker.initialize(config);

Handle Custom Schemes

// Register custom scheme
await deepLinker.registerScheme('myapp');

// Handle custom scheme links
// myapp://profile/123?tab=settings

Platform-Specific Setup

iOS

Add to your ios/Runner/Info.plist:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLName</key>
    <string>com.example.myapp</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>myapp</string>
    </array>
  </dict>
</array>

Android

Add to your android/app/src/main/AndroidManifest.xml:

<activity>
  <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="example.com" />
  </intent-filter>
</activity>

Web

No additional setup required. The package automatically handles web deep linking.

API Reference

DeepLinkConfig

Configuration class for deep linking behavior:

  • schemes: Allowed URL schemes
  • hosts: Allowed host names
  • paths: Allowed path patterns
  • allowCustomSchemes: Enable custom scheme handling
  • allowUniversalLinks: Enable universal links
  • allowAppLinks: Enable app links
  • allowWebLinks: Enable web links
  • allowFileLinks: Enable file links

DeepLinkResult

Result of deep link operations:

  • success: Whether the operation succeeded
  • url: The processed URL
  • scheme: URL scheme
  • host: URL host
  • path: URL path
  • queryParameters: Query parameters
  • error: Error information if failed

FlutterDeepLinkerBase

Main class providing deep linking functionality:

  • initialize(): Initialize the deep linker
  • handleUrl(): Process a deep link URL
  • launchUrl(): Launch a URL
  • getInitialLink(): Get the initial launch link
  • linkStream: Stream of deep link events
  • registerScheme(): Register custom schemes

Examples

class DeepLinkHandler {
  static void handleDeepLink(DeepLinkResult result) {
    if (!result.success) return;
    
    switch (result.path) {
      case '/profile':
        final userId = result.queryParameters?['id'];
        navigateToProfile(userId);
        break;
      case '/product':
        final productId = result.queryParameters?['id'];
        navigateToProduct(productId);
        break;
      case '/search':
        final query = result.queryParameters?['q'];
        performSearch(query);
        break;
    }
  }
}

Custom Scheme Handling

// Register multiple custom schemes
await deepLinker.registerScheme('myapp');
await deepLinker.registerScheme('mycompany');

// Handle different schemes
deepLinker.linkStream.listen((result) {
  if (result.scheme == 'myapp') {
    handleMyAppLink(result);
  } else if (result.scheme == 'mycompany') {
    handleCompanyLink(result);
  }
});

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions, please file an issue on GitHub.


Made with ❤️ by Dhia-Bechattaoui

Libraries

flutter_deep_linker
Advanced deep linking with custom schemes and universal links for Flutter.