Cooking Firebase Dynamic Links in Flutter.

Nikita Gandhi
Flutter Community
4 min readJan 15, 2019

--

If you want to make your product popular, the strategy of mouth publicity is unavoidable part of the marketing campaigns. In the world of technology, referrals are substituted by mouth publicity. The concept of Firebase Dynamic links has basket full of services that help you creating links for referring your product(apps in this case), tracking them and also analysing the growth(app downloads) with multiple categories and filters. You can explore more about Firebase features and functionalities here.

I shall be explaining you an adventurous recipe of making sandwiches(dynamicUrl) and also serving fries and juice(additional tracking parameters) with this healthy dish(dynamicUrl). What’s more crazy? I will be giving you an idea about making a new friend(calling imports) and cooking with it!

  1. Call for help!

Your app depends on a plugin which you have to include inside your pubspec.yaml file.To implement Dynamic links in your Flutter app, import the plugin from here inside the dependencies section.

Including the dependency

Make sure to use the latest version of the plugin.

2. Make friends & accept the help :

Once you have included the dependency, update your project with new package that you have called.

Including the new packages in your project directory

3. Time to use your connection :

Congratulations! You have made an awesome connection. You’re now ready to use the library by creating an import in your dart code.

Get, set, go!

Now that your setup is ready, let’s understand the code you will be implementing to use this plugin successfully!

The link that you will be creating shall navigate to AppStore if opened on an iPhone, PlayStore for Android device for first time user. User will be navigated to website if link is clicked on a desktop.

You can create a Long Dynamic URL or a Short Dynamic URL, whichever suits your ideas and thoughts for app growth.

Dynamic Link will be taking a few parameters for creating the link. Parameters for Android and iOS are necessary for successfully navigating user towards the AppStore or PlayStore if he is a first time user.

A. Domain

Domain is the domain name for your product. Let’s assume here that our product domain is “example.com”. Then you have to mention the domain name as : https://example.page.link.

B. Link :

The link your app will open. Specify a URL that your app can handle, typically the app’s content or payload, which initiates app-specific logic (such as crediting the user with a coupon or displaying a welcome screen). This link must be a well-formatted URL, be properly URL-encoded, use either HTTP or HTTPS, and cannot be another Dynamic Link.

So your link will be : Uri.parse(‘http://example.com/'). The link is added inside the Uri.parse function simply does not parse the link but also creates an Uri object of the string passed. It helps to notify the content provider what exactly we want to access using the link reference.

C. Android Parameters :

Two not to escape parameters for Android are the package name and the minimum OS version restrictions.

packageName: 'com.example', //your project package name
minimumVersion: 25,

D. iOS Parameters :

There are 3 parameters you can provide within the iOS parameters : bundleID, minimumVersion, AppStoreID.

    bundleId: 'com.example',
minimumVersion: '1.0.1',
appStoreId: '1435066055',

Time to Cook :

Now that the basic ingredients are ready, add all these parameters inside the DynamicParameters function.

final DynamicLinkParameters parameters =
DynamicLinkParameters(
domain: 'https://example.page.link',
link: Uri.parse('http://example.com/'),
androidParameters: AndroidParameters(
packageName: 'com.example',
minimumVersion: 25,
),
iosParameters: IosParameters(
bundleId: 'com.example',
minimumVersion: '1.0.1',
appStoreId: '1405860595',
)
);

Turn the flame on :

Now that you have mixed the ingredients this vegetable layered sandwich is now ready. Time to grill the sandwich to bind the ingredients well.

final Uri dynamicUrl = await parameters.buildUrl();

This will help you to bind all the parameters in a single url.

Well dinner is ready to serve. You can share this Url to the audience using a share button in your app.

How about some fries and juice with this perfect healthy recipe?

You can also add googleAnalyticsParameters, itunesConnectAnalyticsParameters, socialMetaTagParameters to get more insights about your app promotion.

Concluding to this blog, thank for patiently reading the blog till the end. Hope you find this blog useful. Remember, including the right and exact parameters will help you building the exact url.

If you are stuck with something feel free to tweet here. You can also mail me here. I soon shall be coming with next article to track the dynamic link generated for your app. Stay tuned :)

--

--

Nikita Gandhi
Flutter Community

Community Manager at Google Developers, Flutter Enthusiast