To start using the Dynamic Links package within your project, import it at the top of your project files:
Before using Dynamic Links, you must first have ensured you have initialized FlutterFire.
By default, this allows you to interact with Dynamic Links using the default Firebase App used whilst installing FlutterFire on your platform.
Android, if you'd like to use Dynamic Links with a secondary Firebase App, use the
Before using Dynamic Links, ensure you have first created a new link prefix on the Firebase Console.
For example, the
my-awesome-app.page.link has been added on this project:
A dynamic link can be created directly from the Firebase Console, or programmatically via the
firebase_dynamic_links plugin. Once a link has been created,
you can use send them to users (via emails, push notifications, in-app content etc.). Upon opening, your application can handle the link however you like, for
example opening a specific screen.
To build a Dynamic Link, use the
FirebaseDynamicLinks.buildLink API in your application code like so:
The method accepts a
DynamicLinkParameters instance, which at a minimum requires a
uriPrefix (defined in the Firebase Console),
along with a
link, which is passed to your application when a user opens the app via a created link.
You can also build a short Dynamic Link which simply makes the Dynamic Link URL shorter. This does entail an additional native SDK
request to the Firebase server whilst the above
buildLink() does not. To build a short Dynamic Link, use the
FirebaseDynamicLinks.buildShortLink API in your application code like so:
To handle a Dynamic Link in your application, two scenarios require implementing.
If the application is terminated, the
method allows you to retrieve the Dynamic Link that opened the application.
This is an asynchronous request, so it makes sense to handle a link before rendering application logic, such as
a navigator. For example, you could handle this in the
Within your application logic, you can then check whether a link was handled and perform an action, for example:
Alternatively, if you wish to identify if an exact Dynamic Link was used to open the application, pass it to
getDynamicLink method instead:
Whilst the application is open, or in the background, you may listen to Dynamic Links events using a stream handler. The
getter returns a
Stream containing a