How to handle deep links in flutter applications using firebase.

varun wani
3 min readNov 27, 2021

What is deep link flutter?

Deep linking is the ability to link into a specific page inside of a native iOS or Android mobile app(as opposed to a mobile website). Deep links let you open up specific content pages (as opposed to a front page of a website) and pass through custom data (shopping item link, reset password from link received from mail, promo codes, etc.)

Lets setup the deep links using firebase.

  1. Register your app with firebase. https://firebase.google.com

2. Create a New Dynamic Link, you can customise your short link URL to make it more professional and contextual. and set up your dynamic link URL with dynamic name.

3. Add behaviour for both ios and android by selecting the app you register.

4. Make sure if you have added Team ID and App store ID for ios application.

Integration of firebase with application.

Refere https://pub.dev/packages/firebase_dynamic_links to add dependency to .yaml file.

For Android-

  • Add google-services.json file in android/app location.Add project level and app level dependencies as well at given location in build.gradle while registering the app.
  • Add intent filter in activity of Androidmanifest.
  • Paste the same link in host you have registered with firebase in dynamic links section.
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /><data android:scheme="http" android:host="deeplinkfluttersample.page.link" /><data android:scheme="https" />
</intent-filter>
  • Add dependencies for both project level and app level build.gradle file.

For IOS-

  • Add GoogleService-Info.plist file in iOS/Runner/ location.
  • Paste the same link in host you have registered with firebase in dynamic links in Associated Domains in signing and capabilities section.
  • use applinks: as prefix while adding link(applinks:deeplinkfluttersample.page.link).

Implementation of code

initDynamicLinks helps to redirect you to the page you define in routing.

void initDynamicLinks() async {
//onLink call if app is in background
FirebaseDynamicLinks.instance.onLink(
onSuccess: (PendingDynamicLinkData? dynamicLink) async {
final Uri? deepLink = dynamicLink?.link;
if (deepLink != null) {
print(deepLink.queryParameters.toString());
Navigator.pushReplacementNamed(context, ResetPasswordScreen.routeName,arguments: deepLink.queryParameters['token']);
}
}, onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
});//getInitialLink called when app is not present in background
final
PendingDynamicLinkData? data =
await FirebaseDynamicLinks.instance.getInitialLink();
final Uri? deepLink = data?.link;
if (deepLink != null) {
print(deepLink.queryParameters.toString())
Navigator.pushReplacementNamed(context, ResetPasswordScreen.routeName,
arguments: deepLink.queryParameters['token']);
}
}

--

--

varun wani

Passionate android developer, in learning phase. Always interested in learning new things