text
stringlengths
1
474
<topic_start>
1. Customize a Flutter application
Write a Flutter app that can handle an incoming URL.
This example uses the go_router package to handle the routing.
The Flutter team maintains the go_router package.
It provides a simple API to handle complex routing scenarios.To create a new application, type flutter create <app-name>.To include the go_router package as a dependency,
run flutter pub add:To handle the routing, create a GoRouter object in the main.dart file:
<code_start>import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() => runApp(MaterialApp.router(routerConfig: router));
/// This handles '/' and '/details'.
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (_, __) => Scaffold(
appBar: AppBar(title: const Text('Home Screen')),
),
routes: [
GoRoute(
path: 'details',
builder: (_, __) => Scaffold(
appBar: AppBar(title: const Text('Details Screen')),
),
),
],
),
],
);<code_end>
<topic_end>
<topic_start>
2. Adjust iOS build settings
Navigate to the Info Plist file in the ios/Runner folder.Update the key to FlutterDeepLinkingEnabled with a Boolean value set to YES.info Note
The FlutterDeepLinkingEnabled property opts into Flutter’s default deeplink handler. If
you are using the third-party plugins, such as uni_links, setting this property will
break these plugins. Skip this step if you prefer to use third-party plugins.Click Associated Domains.Enter applinks:<web domain>. Replace <web domain> with your own domain name.You have finished configuring the application for deep linking.<topic_end>
<topic_start>
3. Hosting apple-app-site-association file
You need to host an apple-app-site-association file in the web domain.
This file tells the mobile browser which iOS application to open instead of the browser.
To create the file, get the app ID of the Flutter app you created in the previous step.<topic_end>
<topic_start>
App ID
Apple formats the app ID as <team id>.<bundle id>.For example: Given a team ID of S8QB4VV633
and a bundle ID of com.example.deeplinkCookbook, The app ID is
S8QB4VV633.com.example.deeplinkCookbook.<topic_end>
<topic_start>
apple-app-site-association
The hosted file should have the following content:Set the appID value to <team id>.<bundle id>.Set the paths value to ["*"].
The paths field specifies the allowed universal links.
Using the asterisk, * redirects every path to the Flutter application.
If needed, change the paths value to a setting more appropriate
to your app.Host the file at a URL that resembles the following:
<webdomain>/.well-known/apple-app-site-associationVerify that your browser can access this file.<topic_end>
<topic_start>
Testing
info Note
It might take up to 24 hours before Apple’s
Content Delivery Network (CDN)
requests the apple-app-site-association (AASA) file from your web domain.
The universal link won’t work until the CDN requests the file.
To bypass Apple’s CDN, check out the alternate mode section.You can use a real device or the Simulator to test a universal link,
but first make sure you have executed flutter run at least once on
the devices. This ensures that the Flutter application is installed.If using the Simulator, test using the Xcode CLI:Otherwise, type the URL in the Note app and click it.If everything is set up correctly, the Flutter application
launches and displays the details screen:<topic_end>
<topic_start>
Appendix
Source code: deeplink_cookbook
<topic_end>
<topic_start>Configuring the URL strategy on the web
Flutter web apps support two ways of configuring
URL-based navigation on the web:<topic_end>
<topic_start>
Configuring the URL strategy
To configure Flutter to use the path instead, use the
usePathUrlStrategy function provided by the flutter_web_plugins library
in the SDK:<topic_end>
<topic_start>
Configuring your web server
PathUrlStrategy uses the History API, which requires additional
configuration for web servers.To configure your web server to support PathUrlStrategy, check your web server’s
documentation to rewrite requests to index.html.Check your web server’s
documentation for details on how to configure single-page apps.If you are using Firebase Hosting, choose the “Configure as a single-page app”
option when initializing your project. For more information see Firebase’s
Configure rewrites documentation.The local dev server created by running flutter run -d chrome is configured to
handle any path gracefully and fallback to your app’s index.html file.<topic_end>
<topic_start>
Hosting a Flutter app at a non-root location
Update the <base href="/"> tag in web/index.html
to the path where your app is hosted.
For example, to host your Flutter app at
my_app.dev/flutter_app, change
this tag to <base href="/flutter_app/">.
<topic_end>
<topic_start>Introduction to animations
Well-designed animations make a UI feel more intuitive,
contribute to the slick look and feel of a polished app,
and improve the user experience.
Flutter’s animation support makes it easy to implement a variety of
animation types. Many widgets, especially Material widgets,