Sub topic 1
What a Deep Link Is and Where It Is Used
Prerequisites
You should know basic Dart and Flutter widgets and Flutter named routes. You should also know the parts of a URL: scheme, host, path, and query.
What a deep link is
A deep link is a URL that opens a specific screen inside an app. A shop might email https://example.com/products/42, and tapping it opens that product page in the installed app. Deep links appear in marketing emails, password reset flows, push notifications, and share buttons.
Custom schemes versus verified HTTPS links
A custom scheme is a made-up prefix such as myshop://products/42. Any app can register the same scheme, so another app can claim your links. A verified HTTPS link uses a domain you own. Your domain publishes a file that approves your app, and the platform checks that file before it routes links to your app. Android calls these App Links, and iOS calls them Universal Links.
Use verified HTTPS links in production. Custom schemes are useful for quick tests.
| Feature | Custom scheme | Verified HTTPS link |
|---|---|---|
| Example | myshop://products/42 | https://example.com/products/42 |
| Ownership check | None | Domain file proves app ownership |
| Opened in a browser | Shows an error | Opens the website |
Reading a URI
Dart's Uri class splits a link into parts. Uri.parse throws a FormatException on invalid text, so catch that error when the input comes from outside your app.
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']); // emailHow Flutter receives a link from the platform
The operating system receives the link and chooses the app that should open it. The platform then passes the URL to Flutter, and the router reads the path to choose a screen.
Mapping URLs to screens with go_router
go_router maps each path pattern to a screen. A segment that starts with : becomes a path parameter, and query values come from state.uri.
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => const Text('Home'),
),
GoRoute(
path: '/products/:id',
builder: (context, state) {
final id = state.pathParameters['id']!;
final ref = state.uri.queryParameters['ref'];
return Text('Product $id, ref: $ref');
},
),
],
);
void main() => runApp(MaterialApp.router(routerConfig: router));Exercise
For the link https://example.com/products/42?ref=email, which router path matches, and what does state.pathParameters['id'] return?
Show answer
The path /products/:id matches. state.pathParameters['id'] returns 42.