Deep Linking in Flutter: A Practical Example
Deep linking is how a URL like https://example.com/product/42 or myapp://profile/7 opens a specific screen in your Flutter app instead of the home screen. Users tap a link in a message, an email, or a browser and expect to land exactly where the link points. Done wrong, the link opens the app but dumps the user on the wrong page, or worse, crashes on cold start.
This guide walks through a working example using Flutter's built-in routing, the Android manifest, iOS Universal Links, and the platform channel that delivers the initial link. You'll get concrete commands to test on both platforms and a realistic sense of where the edge cases hide.
Two Kinds of Links, One Router
Custom schemes like myapp://product/42 are quick to set up and work on both platforms, but they break the moment the app is not installed: the browser shows an error instead of a store page. Universal Links (iOS) and App Links (Android) use your own https domain, so the link works as a normal web page and opens the app only when it is installed. For anything user-facing, prefer https links.
Either way, the app receives a URI string. Your job is to parse it into a route and push it. Keep parsing in one place—a small function that maps path segments to a route name and arguments—so your custom scheme and https links follow the same code path.
- Use https links for shareable content; use a custom scheme only for internal testing.
- Store the host and path prefixes as constants so Android and iOS configs never drift.
- Treat every incoming link as untrusted input: validate IDs before querying.
Android: Manifest, Intent Filter, Verification
For a custom scheme, add an intent-filter inside your main activity with a VIEW action, DEFAULT and BROWSABLE categories, and a data element carrying your scheme and host. For App Links, set android:autoVerify="true" on a filter that declares your https host and path prefix, then host a /.well-known/assetlinks.json file on that domain containing your app's SHA-256 signing certificate. Verification usually happens at install time, though it can take a few minutes.
Two practical notes. Debug builds are signed with a different certificate than release builds, so add both fingerprints to assetlinks.json or App Links will silently fall back to the browser during development. And if you test on an emulator, run adb shell pm get-app-links com.example.app to confirm the domain shows as verified before you blame the Flutter side.
- Include the pathPrefix attribute; without it your filter matches every URL on the domain.
- Keep the intent-filter inside the single FlutterActivity—don't add a second launcher activity.
- After changing the manifest, uninstall and reinstall: verification state is cached.
iOS: Associated Domains and the AASA File
On iOS you enable the Associated Domains capability in Xcode and add applinks:example.com. The domain must serve an apple-app-site-association (AASA) file over HTTPS with no redirects and the correct content type. The file lists your team ID and bundle ID plus the paths you claim. Apple's CDN caches this file, so changes can take from a few minutes up to roughly 24 hours to propagate.
Custom schemes on iOS are configured in Info.plist under CFBundleURLTypes. Universal Links are stricter than Android: a link tapped in Safari's address bar will not open the app, only links tapped inside apps or from other contexts. If a colleague reports 'it doesn't work' on iOS, ask where they tapped the link before touching code.
- Test Universal Links from Notes or Messages, not by typing the URL in Safari.
- Keep AASA paths narrow; a wildcard path sends every domain URL into the app.
- Long-press a link in a browser to see the 'Open in app' option as a quick sanity check.
Receiving the Link in Dart
For cold starts, the link that launched the app arrives through the platform channel before your first frame. For warm starts, the running app gets a callback. Many developers handle only the warm case, test with the app already open, and ship a crash on first launch from a link. Handle both: read the initial link once during startup and subscribe to subsequent links afterward.
A clean pattern is to convert the incoming URI to a route string and hand it to your router. If your app uses a stateful shell, the same state-restoration concerns apply—see Handling Configuration Changes in Kotlin Without Losing State for the Android side of that problem. Keep the initial-link read idempotent so a hot restart does not push the same screen twice.
- Read the initial link before runApp completes, then defer navigation until the first frame.
- Debounce duplicate deliveries; Android can deliver the same intent twice on some OEMs.
- Log the raw URI in debug builds—it saves hours when a path parser misbehaves.
| Link type | Setup file | Verification time | Works if app not installed | Cold-start risk |
|---|---|---|---|---|
| Custom scheme (Android) | AndroidManifest.xml | None | No | Medium |
| Custom scheme (iOS) | Info.plist | None | No | Medium |
| Android App Links | Manifest + assetlinks.json | Minutes to hours | Yes, opens web page | Low |
| iOS Universal Links | Xcode capability + AASA | Up to ~24 hours (CDN) | Yes, opens web page | Low |
| Deferred deep link | Server-side matching | N/A | Yes, after install | High |
Testing Without Waiting for Real Links
You don't need a deployed website to test most of this. On Android, adb shell am start -W -a android.intent.action.VIEW -d "https://example.com/product/42" com.example.app exercises the full intent path, including cold start if you force-stop the app first. On iOS simulators, xcrun simctl openurl booted "myapp://profile/7" does the same for custom schemes.
For Universal Links, you need a real device and a hosted AASA file; simulator support has improved but remains inconsistent across iOS versions. Budget an afternoon for the first end-to-end test, and write down the exact steps—you will repeat them after every signing certificate rotation.
- Force-stop before testing cold start: adb shell am force-stop com.example.app.
- Check logcat for the incoming intent if the app opens but the screen is wrong.
- Rotate signing keys once a year at most; each rotation means updating assetlinks.json.
Where Deep Links Usually Break
The most common failure is a mismatch between the path your link uses and the path your router expects—/product/42 versus /products/42. The second is unencoded parameters: a product name with a slash or space in a query string will split your parser. Always Uri.decodeComponent on values and never concatenate raw segments into a route string.
The third is navigation timing. Pushing a route before the navigator exists throws a null error; pushing after the first frame is safe. If your app also restores state on process death, links can race with restoration. That overlap is the same class of bug covered in StatelessWidget vs StatefulWidget: Which One Should You Pick?—decide explicitly which source of truth wins when both a link and a saved state arrive.
- Normalize trailing slashes before matching.
- Reject unknown routes with a friendly fallback screen, not a crash.
- Version your link format if the app ships to users who update slowly.
Key points
- Prefer https App Links and Universal Links over custom schemes for anything users share.
- Handle the initial link from a cold start; it is the case most examples skip and most bugs come from.
- Validate and decode every path segment before routing—links are untrusted input.
- Force-stop the app and retest after every signing certificate change.
Flutter Screen Widget and Cost Estimator
Estimate the number of widgets in a screen and a rough development-hour figure from your component counts. Adjust the fields to see how each UI area affects the total effort.
Editor and Flutter contributor
Writes practical Flutter tutorials focused on widgets, layout and animation. Enjoys breaking large UI problems into small, testable pieces and explaining them clearly to beginners.