Flutter – Implement Deeplink

Tram Ho

Introduce

For mobile developers, working with deepkinks or applinks is inevitable. Today I will introduce you to an amazing plugin to implement App / Deep Links (Android) Universal Links / Custom URL schemes (iOS). I used a lot when programming with Flutter. That is the plugin uni_links

Proceed

The first thing to do is add uni_links to your project pubspec

To use the deeplink (here we call all the configurations for easy understanding), you need to configure separately for each ios and android platform.

Android

Uni links support both “App Links” and “Deep Links”

  • App Links: Only works with https chema and requires a host specified for your application
  • Deep Links: For the deep link, you can use any custom schema you want without having to request specified host. This can be confusing with other apps so you have to make sure your custom schema is unique.(EX HST0000001://host.com)

To config applink and deeplink for android you go to the file android/app/src/main/AndroidManifest.xml: and add the following intents

Properties android:host is optional for Deep link and required for app link

For more specificity, you can add properties android: pathPrefix: to enter

IOS

Similar to android, uni links also supports two other types on iOS, “Universal Links” and “Custom URL schemes”.

  • Universal Links also just works with the ‘https’ schema and requests a specified host, the permissions and the files stored apple-app-site-association
  • Custom URL schemes : Similar to Android’s deep link, you can use any custom schema you want

For Universal Links you need to add or create access to the com.apple.developer.associated-domains domain through Xcode or edit the ios / Runner / Runner.entitlements file.

For Custom URL schemas you need to specify your schema in the ios / Runner / Info.plist file

Use in Flutter

The config for each platform is done, now you just need to implement it in the flutter so that the app can capture the link

There are two cases where the app will get the link: App has not yet started and the app is running in the background.

Initial Link (String) => Returns the link when the application is started, if any

Initial Link (Uri) => Similar to getInitialLink, but the link is converted to Uri type

On change event (String) # => Listen for Link changes, usually use this

On change event (Uri) => Similar to On change event (String) ”

Below is a full example of how to implement, extremely simple, please take a look

Thank you for watching Source: https://pub.dev/packages/uni_links

Share the news now