# Installation

Detour provides a Flutter plugin (`detour_flutter_plugin`) that bridges native Detour SDK behavior on Android and iOS.

:::note[Beta]
Flutter Plugin version `1.1.1` is currently in beta. API and integration details may still change before stable release.
:::

Before installation, make sure your app is created in the Detour Dashboard and you have:

- `appID` from **API configuration**
- publishable `apiKey` from **API configuration**
- platform integration snippets from **App configuration**

## Requirements

- Flutter: `>=3.3.0`
- Dart: `^3.11.1`
- Android min SDK: `24`
- iOS: `13.0+`

## Install package

Add the package to your `pubspec.yaml`:

```yaml
dependencies:
  detour_flutter_plugin: ^1.1.1
```

Then run:

```bash
flutter pub get
```

## Native SDK dependencies

`detour_flutter_plugin` wraps native Detour SDKs:

- Android bridge depends on `com.swmansion.detour:detour-sdk:1.0.1`.
- iOS bridge depends on `Detour` CocoaPod (`~> 1.0.2`), pulled automatically via the plugin podspec.

For Android dependency resolution, keep `google()` and `mavenCentral()` in your project repositories.

For iOS integration updates, run:

```bash
cd ios
pod install
cd ..
```

## App config

Use your credentials in `DetourConfig`:

```dart
const DetourConfig(
  apiKey: '<REPLACE_WITH_YOUR_API_KEY>',
  appID: '<REPLACE_WITH_APP_ID_FROM_PLATFORM>',
  shouldUseClipboard: true,
  linkProcessingMode: LinkProcessingMode.all,
)
```

## Platform integration

The plugin handles bridge wiring, but your app still needs native deep-link setup:

- Android:
  - App Links intent-filter from Dashboard
  - optional custom scheme intent-filter (if you use scheme links)
- iOS:
  - Associated Domains (`applinks:<domain>`)
  - `CFBundleURLTypes` for custom scheme links
  - if you override AppDelegate/SceneDelegate deep-link callbacks, always forward to `super`

### iOS delegate forwarding (required when overriding)

Flutter plugins (including Detour) receive lifecycle callbacks through Flutter delegate chain.  
If you override iOS deep-link callbacks, return `super` result:

```swift
override func application(
  _ app: UIApplication,
  open url: URL,
  options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
  return super.application(app, open: url, options: options)
}

override func application(
  _ application: UIApplication,
  continue userActivity: NSUserActivity,
  restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
  return super.application(
    application,
    continue: userActivity,
    restorationHandler: restorationHandler
  )
}
```

Reference implementation:
- [AppDelegate.swift (example app)](https://github.com/software-mansion-labs/detour-flutter-plugin/blob/v1.1.1/example/ios/Runner/AppDelegate.swift)
- [SceneDelegate.swift (example app)](https://github.com/software-mansion-labs/detour-flutter-plugin/blob/v1.1.1/example/ios/Runner/SceneDelegate.swift)

:::note[Clipboard on iOS 14+]
On iOS 14+, clipboard matching uses `detectPatterns` before reading pasteboard content. Actual clipboard value is read only when probable URL is detected.
:::

## Next steps

1. Integrate startup/runtime flow in [Usage](https://detour.swmansion.com/docs/sdk/flutter/sdk-usage).
2. Start from the runnable app in [Examples](https://detour.swmansion.com/docs/sdk/flutter/examples).