You can create short or long Dynamic Links with the Firebase Dynamic Links Builder API. This API accepts either a long Dynamic Link or an object containing Dynamic Link parameters, and returns URLs like the following examples:
https://example.com/link/WXYZ
https://example.page.link/WXYZ
Set up Firebase and the Dynamic Links SDK
Before you can create Dynamic Links in your Android app, you must include the Firebase SDK. If your app is set up to receive Dynamic Links, you have already completed these steps and you can skip this section.
-
Install and initialize the Firebase SDKs for Flutter if you haven't already done so.
-
From the root directory of your Flutter project, run the following command to install the Dynamic Links plugin:
flutter pub add firebase_dynamic_links
-
If you're building an Android app, open the Project settings page of the Firebase console and make sure you've specified your SHA-1 signing key. If you use App Links, also specify your SHA-256 key.
-
In the Firebase console, open the Dynamic Links section.
-
If you have not already set up a domain for your Dynamic Links, click the Get Startedbutton and follow the prompts.
If you already have a Dynamic Links domain, take note of it. You need to provide a Dynamic Links domain when you programmatically create Dynamic Links.
-
Recommended: From the "More" (⋮) menu, specify the URL patterns allowed in your deep links and fallback links. By doing so, you prevent unauthorized parties from creating Dynamic Links that redirect from your domain to sites you don't control.
-
Create a Dynamic Link from parameters
To create a Dynamic Link, create a new DynamicLinkParameters
object and pass it to buildLink()
or buildShortLink()
.
The following minimal example creates a long Dynamic Link to https://www.example.com/
that opens with com.example.app.android
on Android
and the app com.example.app.ios
on iOS:
final
dynamicLinkParams
=
DynamicLinkParameters
(
link:
Uri
.
parse
(
"https://www.example.com/"
),
uriPrefix:
"https://example.page.link"
,
androidParameters:
const
AndroidParameters
(
packageName:
"com.example.app.android"
),
iosParameters:
const
IOSParameters
(
bundleId:
"com.example.app.ios"
),
);
final
dynamicLink
=
await
FirebaseDynamicLinks
.
instance
.
buildLink
(
dynamicLinkParams
);
To create a short Dynamic Link, pass the DynamicLinkParameters
object to buildShortLink()
. Building the short link requires a network call.
For example:
final
dynamicLinkParams
=
DynamicLinkParameters
(
link:
Uri
.
parse
(
"https://www.example.com/"
),
uriPrefix:
"https://example.page.link"
,
androidParameters:
const
AndroidParameters
(
packageName:
"com.example.app.android"
),
iosParameters:
const
IOSParameters
(
bundleId:
"com.example.app.ios"
),
);
final
dynamicLink
=
await
FirebaseDynamicLinks
.
instance
.
buildShortLink
(
dynamicLinkParams
);
By default, short Dynamic Links are generated with suffixes that are only a few characters long. Although this makes links more compact, it also introduces the possibility that someone could guess a valid short link. Often, there's no harm if someone does so, because the link leads to public information.
However, if your short links lead to user-specific information, you should
create longer links with 17-character suffixes that make it very unlikely that
someone can guess a valid Dynamic Link. To do so, pass ShortDynamicLinkType.unguessable
to the buildShortLink()
method:
final
unguessableDynamicLink
=
await
FirebaseDynamicLinks
.
instance
.
buildShortLink
(
dynamicLinkParams
,
shortLinkType:
ShortDynamicLinkType
.
unguessable
,
);
Dynamic Link parameters
You can use the Dynamic Link Builder API to create Dynamic Links with any of the supported parameters. See the API reference .
The following example creates a Dynamic Link with several common parameters set:
final
dynamicLinkParams
=
DynamicLinkParameters
(
link:
Uri
.
parse
(
"https://www.example.com/"
),
uriPrefix:
"https://example.page.link"
,
androidParameters:
const
AndroidParameters
(
packageName:
"com.example.app.android"
,
minimumVersion:
30
,
),
iosParameters:
const
IOSParameters
(
bundleId:
"com.example.app.ios"
,
appStoreId:
"123456789"
,
minimumVersion:
"1.0.1"
,
),
googleAnalyticsParameters:
const
GoogleAnalyticsParameters
(
source
:
"twitter"
,
medium:
"social"
,
campaign:
"example-promo"
,
),
socialMetaTagParameters:
SocialMetaTagParameters
(
title:
"Example of a Dynamic Link"
,
imageUrl:
Uri
.
parse
(
"https://example.com/image.png"
),
),
);
final
dynamicLink
=
await
FirebaseDynamicLinks
.
instance
.
buildShortLink
(
dynamicLinkParams
);
You can set Dynamic Link parameters with the following methods:
https://example.com/link https://example.page.link
setMedium
setCampaign
setTerm
setContent
setAffiliateToken
setCampaignToken