Mastering Flutter Deep Linking: A Comprehensive Guide

Deep links are revolutionizing the landscape of mobile applications, with flutter deep linking leading the way. Imagine this scenario: a friend shares a link to a product. You click it, and presto! You’re not just inside the app but directly viewing that specific product. Sounds like magic? No, it’s the power of deep linking!

In Flutter, deep links act as direct pathways to precise app content or functionalities, crucial for apps with easily shareable content. They facilitate seamless in-app experiences when users share links, supporting everything from promotional campaigns to content shortcuts. This guide aims to explains flutter deep linking, covering everything from setting up native functionality for Android and iOS to managing navigation with GoRouter.

Deep links not only simplify navigation but also foster user retention, enhance engagement, and streamline content sharing. Whether you’re creating your initial deep link or refining existing ones, this guide serves as the ultimate roadmap to deep linking success.

Composition of a Flutter Deep Linking

A deep link redirects users to a specific destination within an app rather than a webpage.

Deep links comprise a URL, a string of characters, which includes:

Protocol: This marks the beginning of the link, commonly seen as http or https. It specifies the protocol to utilize when accessing the resource online.

Domain: This denotes the domain name of the link. For instance, codewithandrea.com represents the domain, indicating the location of the resource.

Path: This identifies the precise resource within the domain that the user wishes to access. In our instance, /careers/ serves as the path.

Additionally, there are:

Query Parameters: These are supplementary options appended after a ? mark, typically aiding in data sorting or filtering.

Port: This facilitates communication with the server’s network services. While often omitted, HTTP and HTTPS default to ports 80 and 443, respectively.

Fragment: Also known as an anchor, this optional segment follows a # symbol and focuses on a specific part of a webpage.

Here’s an annotated illustration showcasing all the aforementioned elements:

An instance of a complete URL with protocol, domain, port, path, query parameters, and fragment.

Understanding the Structure of a Link Equips You to Manage it Effectively Within Your Flutter App

During the initial stages of your project, you might influence how the URL is constructed to ensure simplicity and ease of handling.

It’s worth noting that while some URLs are well-designed, others may pose challenges when integrated into your app. Stay tuned for the implementation section of this guide to witness how it’s executed in flutter deep linking.

Varieties of Deep Links

Mobile apps can accommodate two types of deep links based on the utilized scheme.

Deep links encompass regular web links. Custom Schemes:

In Android, this is referred to as a deep link, while in the iOS realm, it’s termed a custom URL scheme. This approach proves advantageous if you lack a domain but seek to leverage the potential of deep links.

You have the liberty to select any Custom Scheme, provided you define it within your app. The setup process is swift since uniqueness isn’t a concern.

However, a downside is its diminished security, as any application could hijack your Custom Scheme and endeavor to open your links. Additionally, if a user lacks your app and clicks on a Custom Scheme link, they’ll encounter a dead end accompanied by an error message. While not ideal, its simplicity renders it convenient for rapid tests.

HTTP/HTTPS Scheme

Known as App Links on Android and Universal Links on iOS, this method furnishes the most secure approach to integrating deep link support into your mobile app.

A mobile application must fulfill both domain ownership and authentication requirements. The manifest file on Android must contain the domain name and the associated domains file on iOS must contain the associated domain name.

By engaging in this synchronization, your app acknowledges the domain, and the domain authenticates your app. This bidirectional validation ensures the integrity and legitimacy of the deep links, offering a secure deep-linking experience.

Sufficient with the theory; let’s delve into platform configuration!

Setting Up Deep Links on Android

Let’s commence by adjusting the AndroidManifest.xml file:

Access the android/app/src/main/AndroidManifest.xml file.
Incorporate an intent filter into your activity tag. Specify your scheme and domain.
Optional: delineate supported paths.

The intent filter should resemble this:

If opting for a Custom Scheme and aiming to open links like yourScheme://yourDomain.com, utilize:

The foregoing example doesn’t specify particular paths. With this setup, your app can access all URLs from your domain. This is often undesirable, and for greater control, you must define the accepted paths by integrating relevant path tags. The most prevalent ones include path, pathPattern, and pathPrefix.

You can locate a detailed guide on utilizing various data tags in the official Android documentation.

Android Server Verification

You must ensure your domain recognizes your app as a trustworthy URL handler now that the app recognizes the types of URLs it should handle.

It’s essential to note that this step solely pertains to HTTP/HTTPS links and not custom schemes.

Step 1: Generate a new file named assetlinks.json. This file should encompass the digital asset links associating your site with your app. It should contain the following:

Swap out “com.example” with your app’s package name, and replace the sha256_cert_fingerprints value with your app’s unique SHA256 fingerprint.

Step 2: Your website must contain the assetlinks.json file. It must be accessible via https://yourdomain/.well-known/assetlinks.json. If you’re unsure how to execute this, contact your domain’s administrator.

Step 3: To validate if the assetlinks.json is correctly configured, utilize the statement list tester tool provided by Google.

SHA256 fingerprints can be generated by using this command: grandle signingReport.

Using the Developer Console, you can access your production app’s app signing under Setup > App Integrity > App Signing.

How to Validate Deep Links on Android

Ready to verify your deep links on Android? Simply launch an Android emulator and execute these commands via the terminal.

  1. For HTTP/HTTPS links:
  2. For Custom Schemes:

Heads up! ADB typically resides in the android/sdk/platform-tools directory. Ensure this directory is in your system path before executing these commands.

Encountering an “adb: more than one device/emulator” obstacle? If you’re concurrently operating multiple Android devices or emulators, peruse this thread for a resolution.

An alternative method to test is by sending the link https://yourDomain.com to yourself using any app (such as WhatsApp) and subsequently clicking on it. Initially, the aim is for the app to activate. We’ll later delve into how to navigate to the appropriate screen with flutter code.

🔸Potential concern🔸

If tapping the URL activates your app “within” the source app (such as Gmail or WhatsApp) rather than independently, append android:launchMode=”singleTask” within your <activity> tag.

The subsequent example depicts the app’s appearance after being activated with a deep link from WhatsApp:

Related read: How to Create Deeplinks for Android Using Branch.io?

Understanding the Disambiguation Dialogue

The disambiguation dialogue is a prompt displayed by Android when a user possesses multiple apps capable of handling a specific link. It enables users to select their preferred application.

To circumvent this, you should make your app the default handler for the link. While this action entails user consent, it streamlines the user experience, ensuring a smoother navigation process.

Before initiating this, consider its repercussions. Once your app becomes the default handler, users must actively revoke this privilege to enable other apps to manage these links.

Custom Scheme Integration

If you’re following the Custom Scheme approach, you don’t need to validate your server’s URLs. Instead, after appending the intent filter to AndroidManifest.xml, the integration process is complete.

Subsequently, your app can handle custom-scheme links without further ado.

Congrats! You’ve laid the foundation for deep link integration within your Android app. You’ve configured the AndroidManifest.xml file to intercept incoming links and direct users to the appropriate screens.

Next up, we’ll explore deep linking on iOS and highlight the contrasts and similarities between the two platforms.

Transform Your Mobile App Navigation with Flutter Deep Linking. Hire Our Developers Now!

Setting Up Deep Links on iOS

Integration within iOS necessitates a nuanced approach due to divergent terminology and methods.

On iOS, deep links are categorized as either Universal Links (recommended) or custom URL schemes. While custom URL schemes remain prevalent, Apple advocates for Universal Links due to their enhanced security and user experience.

Universal Links

Universal Links closely mimic standard web URLs and operate in conjunction with the website’s domain. They proffer a seamless transition from web to app, thereby enriching the user experience.

Key Benefits:

Enhanced Security: Universal Links leverage standard HTTPS authentication mechanisms, safeguarding against potential security threats.

User Experience: Unlike custom URL schemes, Universal Links eschew abrupt app openings. Instead, they incorporate a redirection step, ensuring a seamless user experience.

Referrer Information: Universal Links preserve referrer information, affording app developers insights into traffic sources.

Before delving into Universal Link integration, ensure the following prerequisites are satisfied:

Apple Developer Account: To access capabilities, create an Apple Developer account if you haven’t already.

App ID Configuration: In the Apple Developer Center, configure your App ID to support Associated Domains. This is pivotal for Universal Link integration.

Apple App Site Association (AASA) File: Craft an AASA file and host it on your domain. This file encompasses JSON data specifying the association between your website and the app.

Domains Validation: In the Xcode project, list your domain under Associated Domains.

Implementation Overview:

To summarize, here’s an outline of the Universal Link integration process:

  1. Generate the Apple App Site Association (AASA) file and host it on your domain.
  2. Configure your Xcode project settings to recognize Associated Domains.
  3. Incorporate the necessary entitlements in your Xcode project.
  4. Validate the integration via the Apple App Site Association Validator.

Let’s delve into each step in detail!

Generating the Apple App Site Association (AASA) File:

The AASA file is pivotal for Universal Link integration, establishing the association between your website and your app. It’s a JSON file comprising the following structure.

Here’s an example of an AASA file:

{
"applinks": {
"apps": [],
"details": [
{
"appID": "TeamID.BundleID",
"paths": ["*"]
}
]
}
}

Replace “TeamID” with your Apple Developer Team ID and “BundleID” with your app’s bundle identifier.

The “paths” attribute signifies the paths within your domain that should be handled by your app. The asterisk (*) denotes all paths.

Host the AASA file at the root level of your website. It should be accessible via the URL https://yourDomain.com/apple-app-site-association.

Configuring Xcode Project Settings:

In the Xcode project, configure Associated Domains to authenticate the association between your app and your website.

  1. Navigate to the “Signing & Capabilities” tab in Xcode.
  2. Click the “+” button to add a new capability.
  3. Choose “Associated Domains” from the list.
  4. Add your domain preceded by “applinks:” as the associated domain.

Here’s an illustrative example:

In this scenario, “yourDomain.com” represents your website’s domain.

Incorporating Entitlements:

The entitlements file, entitlements.plist, is pivotal for Universal Link integration. It ensures seamless communication between your app and your website.

If your project lacks an entitlements file, create one via File > New > File > iOS > Resource > Property List.

Next, incorporate the following entitlements:

Application Associated Domain: This entitlement authorizes your app to handle Universal Links.

Paste the associated domain(s) from the previous step into this entitlement. Ensure they’re prefixed with “applinks:”.

Here’s an example of an entitlements file:

Validating the Integration

To validate your Universal Link integration, utilize the Apple App Site Association Validator:

  1. Navigate to https://branch.io/resources/aasa-validator/.
  2. Input your website’s domain.
  3. Click “Validate.”

If the validation succeeds, proceed to test the integration on an iOS device.

Testing Universal Links

Testing Universal Links necessitates an iOS device running iOS 9 or later. Simulator testing isn’t viable due to inherent limitations.

Here’s a step-by-step guide to testing Universal Links:

  1. Build and install your app on a physical iOS device.
  2. Ensure the device is connected to the internet.
  3. Access a Universal Link (e.g., https://yourDomain.com/path) via Safari or another web browser on the device.
  4. Verify if the link redirects to your app.
  5. If the redirection is successful, your Universal Link integration is operational.

Congratulations! You’ve successfully integrated Universal Links into your iOS app, enriching user experience and streamlining the transition from web to app.

Universal Links offer enhanced security, seamless user experience, and valuable referrer information, making them the preferred choice for deep linking on iOS.

In the subsequent section, we’ll explore navigation management within Flutter, enabling seamless traversal between screens via deep links.

Managing Navigation with GoRouter

GoRouter serves as a robust navigation solution for flutter apps, seamlessly integrating deep links into your application.

Key Features:

Declarative Routing: Define routes via a simple, declarative syntax, enhancing code readability and maintainability.

Deep Link Integration: GoRouter seamlessly integrates flutter deep linking into your flutter app, facilitating seamless traversal between screens.

Custom Transition Animation: Tailor transition animations to match your app’s design aesthetic, ensuring a cohesive user experience.

State Restoration: Preserve navigation state across app restarts, mitigating user frustration and enhancing usability.

To incorporate GoRouter into your Flutter app, follow these steps:

1. Install the GoRouter package via pubspec.yaml:

dependencies:
go_router: ^2.1.0

2. Define routes within your app using the GoRouter syntax.

3. Implement deep link handling logic within your app, parsing incoming deep links and navigating to the appropriate screens.

Here’s an illustrative example of deep link integration using GoRouter:

The foregoing example defines two routes: “/” and “/details”, corresponding to the home screen and details screen, respectively.

Upon receiving an incoming deep link, parse the link’s path and navigate to the corresponding screen using GoRouter’s navigation API.

Congratulations! You’ve successfully integrated flutter deep linking into your flutter app using GoRouter, enabling seamless navigation between screens via deep links.

GoRouter’s declarative syntax, deep link integration, custom transition animation, and state restoration capabilities make it a robust navigation solution for flutter apps.

In the subsequent section, we’ll explore deep link attribution and analytics, enabling you to track user engagement and optimize your flutter deep linking strategy.

coma

Conclusion

Deep linking in Flutter enhances user experience by allowing direct navigation to specific content within an app. This guide explains how to set up and manage deep links for Android and iOS, including creating URLs, configuring necessary files, and handling different types of deep links.

Deep links streamline app navigation, improve user retention, and simplify content sharing. By following this guide, you can set up deep links, validate them, and use tools like GoRouter to manage navigation within your Flutter app. This comprehensive approach ensures a smooth and secure deep-linking experience for users.

Keep Reading

Keep Reading

  • Service
  • Career
  • Let's create something together!

  • We’re looking for the best. Are you in?