Sub topic 1
What a Deep Link Is and Where It Is Used
Prerequisites
This chapter assumes you can read basic Dart and build a simple Flutter app. You should know the parts of a URL (scheme, host, path, query) and have used Navigator with named routes. Later chapters ask you to run the app on an Android emulator or device and on an iOS simulator or device. For verified links you also need a web domain you control. This chapter needs none of these setups. It builds the working model that the rest of the tutorial relies on.
What a deep link is
A deep link is a URL that opens an app at a specific screen instead of at its home screen. Opening https://example.com/products/42 and landing on the detail page for product 42 is a deep link at work. Opening the app and then tapping through menus to find the product is not.
Three parts are involved:
- The link. A URL that someone sends, scans, taps, or receives.
- The operating system. It decides which app, if any, handles the link.
- The app. It receives the URL and turns it into a screen.
Flutter only handles the third part. The operating system makes the first decision, so most deep link bugs happen before Flutter code runs. Keep this in mind. When a link opens a browser instead of your app, the cause is usually configuration on the Android or iOS side or on your web server, not your Dart code.
Where deep links are used
Deep links show up wherever something outside your app needs to point at something inside it.
| Source | Example | What the user expects |
|---|---|---|
| Email and messages | "Your order shipped" with a link to `/orders/981` | The order screen opens directly |
| Push notifications | A notification about a new comment | The thread containing that comment opens |
| QR codes | A code on a poster or product box | The matching product or event page opens |
| Web pages | A "Open in app" banner on your mobile site | The same content opens in the app |
| Other apps | A chat app showing a link you shared | Your app opens instead of a browser |
| Marketing campaigns | An ad with a promo code in the query | The promo screen opens with the code applied |
| Password reset | A link with a one-time token | The reset form opens with the token filled in |
All of these share one property: the sender cannot know where the user currently is in your app. The link must carry enough information to reach the right screen from nothing.
What a deep link does and does not do
A deep link gets the user to a screen. It does not make the content appear, log the user in, or create state that the screen needs. Your app must still do these things:
- Load the data for product 42.
- Decide what to show if the user is signed out.
- Show something sensible if product 42 no longer exists.
Later chapters cover each of these. For now, treat a deep link as an input to your app, in the same way a button tap is an input. Like any input, it can be missing, wrong, or hostile.
Two kinds of links
Two kinds of links reach an app, and the rest of the tutorial keeps returning to the difference.
Custom scheme links look like myapp://products/42. The scheme myapp is something you invented. They are easy to set up, because you register the scheme in the app and you are done. They have two drawbacks. Any app can claim the same scheme, so another app may open your link instead of yours. And if your app is not installed, the link fails or shows an error, because no web page exists behind it.
Verified HTTPS links look like https://example.com/products/42. They are ordinary web URLs. Android calls them App Links, and iOS calls them Universal Links. The operating system opens your app only if your website publishes a file that names your app, which proves that you control both. If the app is not installed, the same URL opens in the browser, so you can serve a normal web page.
| Property | Custom scheme | Verified HTTPS link |
|---|---|---|
| Example | `myapp://products/42` | `https://example.com/products/42` |
| Setup effort | Low | Higher (server file plus app config) |
| Ownership proof | None | Required |
| App not installed | Link fails | Opens a web page |
| Safe against other apps claiming it | No | Yes |
| Works in browsers and messaging apps | Often blocked or shown as plain text | Yes |
For public production links, prefer verified HTTPS links. Custom schemes remain useful for development, for links between apps you control, and for older setups. The next chapter compares the two in detail.
How a link travels to a screen
Whatever the source, an incoming link follows the same path.
Each step maps to a later chapter:
- The check in step B is covered by the chapters on Android App Links and iOS Universal Links.
- Step E is how Flutter receives a link from the platform.
- Steps F to I are the router, parameters, and unknown-link handling.
A first look at the data a link carries
A link is only text until your app parses it. Dart's Uri class does this work. This example splits a link into the parts a router needs.
void main() {
final uri = Uri.parse('https://example.com/products/42?ref=email');
print(uri.scheme); // https
print(uri.host); // example.com
print(uri.pathSegments); // [products, 42]
print(uri.queryParameters['ref']); // email
}The path /products/42 tells the router which screen to build, and 42 tells that screen which product to load. The query ref=email is extra information, in this case where the click came from. A router such as go_router does this parsing for you. The code above shows what it works from.
Deep links compared with named routes
If you have used Navigator.pushNamed(context, '/products'), you have already seen something close to a deep link. The difference is who starts the navigation.
| Row | Named route in a running app | Deep link |
|---|---|---|
| Started by | Your code, after a tap | The operating system, from outside |
| App state when it happens | Known, since the user is already in the app | Unknown: the app may be closed, or the user may be anywhere |
| Input you control | Yes | No, anyone can craft a URL |
| Stack of screens | Built by your own pushes | Must be built from the URL alone |
The last row causes trouble in practice. If a link opens a product page directly, pressing Back must still go somewhere sensible. A declarative router helps because it derives the whole screen stack from the URL, rather than from a series of pushes.
Common mistakes to avoid
These problems appear often in first implementations. Each one has a full chapter later.
- Testing only in the running app. A link that works while the app is open can fail on a cold start, when the app launches because of the link.
- Assuming the link is trustworthy. A URL is user-controlled input. Validate it before you act on it, especially for actions such as password resets or payments.
- Forgetting signed-out users. A link to a private screen needs a login step and a way to return to the original destination afterwards.
- Configuring only the app. Verified links need a file on your web server. Without it, the operating system opens the browser and your Dart code never runs.
- No fallback. Old, mistyped, or removed URLs reach your app. An unknown path should lead to a helpful screen, not a crash or a blank page.
What the rest of the tutorial builds
The chapters that follow build one working deep link setup in order. You will compare the link types, parse URIs, learn how the platform hands links to Flutter, and map URLs to screens with go_router. Then you will configure Android and iOS, handle cold and warm starts, add login redirects and fallbacks, test from the command line, and secure the result. The final chapters touch on Flutter web and on links that must survive an app install.
Exercise
A user taps https://example.com/products/42 in a chat app on a phone where your app is installed, but the link opens in the browser. Without looking at any Dart code, name two places you would check first and explain why.
Show answer
Check the platform configuration and the web server. On Android, look for the intent filter in AndroidManifest.xml and the assetlinks.json file on the domain. On iOS, look for the Associated Domains entitlement and the apple-app-site-association file. The operating system decides whether to open the app before Flutter receives anything, so a missing or wrong verification file or app setting sends the link to the browser, and no Dart code runs.
Exercise
Give two reasons that a verified HTTPS link is a better choice than a custom scheme such as myapp://products/42 for a link in a public marketing email.
Show answer
First, the operating system opens your app only after confirming that your domain authorizes it, so another app cannot claim the same link. Second, if the app is not installed, an HTTPS link still opens a web page in the browser, while a custom scheme link fails. Email clients also handle HTTPS links reliably and may not make custom schemes tappable.
Exercise
Using Uri.parse on 'https://example.com/orders/981?utm=sms', what do uri.pathSegments and uri.queryParameters['utm'] return?
Show answer
uri.pathSegments returns [orders, 981], a list of two strings, and uri.queryParameters['utm'] returns the string sms.