Credits: https://unsplash.com/photos/8bghKxNU1j0

Sharing App Content Using Dynamic/Deep Links in Flutter

Samveg Thaker
Zenithec Techware
Published in
5 min readApr 4, 2021

--

What are deep or dynamic links? Why are they used, and how to implement them in your application? Can you get analytics out of that?

Let me answer all of this one by one.

Pre-requisites:

  1. Basics of Flutter
  2. Code structure for Flutter

What are Deep/Dynamic Links?

According to Firebase, it is

Firebase Dynamic Links are links that work the way you want, on multiple platforms, and whether or not your app is already installed.

It is a way to share application information with people who might or might not have your application. You can track who shared what content and how many of these links were clicked and not clicked.

Credits: https://www.youtube.com/watch?v=LvY1JMcrPF8

Why are they used?

Well, there a couple of usages. The one we will be discussing here is App Content Sharing. You must have seen various applications like Zomato, Swiggy, Airbnb and what not sharing different restaurants and staying places and accessing those links directly lead you to that particular restaurant.

Or you might have seen that you can share some Instagram posts, LinkedIn posts and all social media posts via links. The link directly leads you to a particular post. It is one of the very crucial features of an application.

How do you do it?

Let’s focus on each step very carefully. I am setting up the Firebase Project on https://console.firebase.google.com.

Setting up a firebase project

You can find a detailed note of Projects in Firebase here. So you need to create a project for both Android and iOS.

It’s a 3 step process:

  1. Getting the name for your project — “Testing”
Naming a test project on https://console.firebase.google.com

2. You can enable google analytics so that you can know a lot of valuable statistics. But again, it depends on your use case and preference.

Enabling Google Analytics

3. [OPTIONAL] If you enable analytics in the previous step, you will need an analytics account to select where you want the data to go.

After you create a project, it might look like this:

Firebase console landing page.

You can add the Package Path for Android and BundleId for iOS to identify your PlayStore or Apple App Store application. What’s next?

Creating Dynamic Links

Select the project you created. And on the side of Nav Bar, choose the option Dynamic Links in the Engage section. You will get something like the below:

Starting with Dynamic Links
  1. Click on Get Started.

2. Now, you must have a Domain, the details of which will be required here. Enter a valid domain that you own like below. You can add anything like “subdomain.domain.com” where the subdomain is not compulsory.

I am adding the domain.

Note: You don’t need to add https:// or http:// as a prefix.

3. You will be asked to choose a path prefix if you like. But you can skip it since we will be dynamically creating links from our application. Like below, just press Continue.

Setting Path prefix

4. Now, you will be asked to set up the DNS for this. You can be asked to add a TXT, A or some other type of record in your DNS.

Value for DNS

5. While adding a record in DNS, make sure, if you have added a subdomain in the 1st step, you will keep the host/Name will be the subdomain. If you are not using a subdomain, use @ as Name and the value can be copied as given to you. Click Verify once done.

Awesome. Now you can create Dynamic links, and once the domain is verified, it might take up to 24 hours to get verified.

For setting up on iOS, follow the section linked here.

Let’s code!

1st thing would be to create a function that generates a Dynamic link. We will add the dependency of this from

in the pubspec.yaml like

dependencies:
firebase_dynamic_links: ^0.8.0

We can add a standard function that can generate a dynamic link from anywhere in the application like below.

You can pass any number of query parameters in the link, depending upon your use case. I have shared 1 query param for simplicity. Now, this function will create a dynamic link.

Let us assume a scenario where we have to share a post/feed. So, what should happen on clicking the share button? We will be using the “Share” library in Flutter to share the links within different applications.

You can use it like below by adding it as a dependency in the pubspec.yaml

dependencies:
firebase_dynamic_links: ^0.8.0
share: ^2.0.1

Then you can create a function in the HelperClass.dart to use it at different places in your application.

Now we need to call these function from some button clicks.

Now, you are good to go and can share them as messages on Whatsapp, Telegram and everywhere. But how will the receiver know on what feed or post to open?

Receiving the Dynamic Links

Go to the starter dart file of your application (main.dart in my case). We will be adding a function to receive the dynamic links and open the desired content.

Kudos! You did it. The feature will be soon available on our application Avasar.life, and you can test it out from the link below.

--

--

Samveg Thaker
Zenithec Techware

Entrepreneur | SE at Microsoft | Ex-DSC Lead | Winner of SIH2019 | Android Developer