Viewing version 3.3.0. Open the latest package page.

app_links

3.3.0

Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler for Flutter (desktop included).

Download archive

Readme

app_links

Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler (desktop included).

This plugin allows you to:

  • catch HTTPS URLs to open your app instead of the browser (App Link / Universal Link).
  • catch custom schemes to open your app (Deep Link / Custom URL scheme).

Getting Started

Before using the plugin, you'll need to setup each platforms you target.

Android

iOs

Windows

Don't be afraid, this is just copy/paste commands to follow.
But yes, it we will be a bit painful...

Declare this method in <PROJECT_DIR>\windows\runner\win32_window.h

  // Dispatches link if any.
  // This method enables our app to be with a single instance too.
  // This is optional but mandatory if you want to catch further links in same app.
  bool SendAppLinkToInstance(const std::wstring& title);

Add this inclusion at the top of <PROJECT_DIR>\windows\runner\win32_window.cpp

#include "app_links_windows/app_links_windows_plugin.h"

Add this method in <PROJECT_DIR>\windows\runner\win32_window.cpp

bool Win32Window::SendAppLinkToInstance(const std::wstring& title) {
  // Find our exact window
  HWND hwnd = ::FindWindow(kWindowClassName, title.c_str());
  
  if (hwnd) {
    // Dispatch new link to current window
    SendAppLink(hwnd);

    // (Optional) Restore our window to front in same state
    WINDOWPLACEMENT place = { sizeof(WINDOWPLACEMENT) };
    GetWindowPlacement(hwnd, &place);
    switch(place.showCmd) {
      case SW_SHOWMAXIMIZED:
          ShowWindow(hwnd, SW_SHOWMAXIMIZED);
          break;
      case SW_SHOWMINIMIZED:
          ShowWindow(hwnd, SW_RESTORE);
          break;
      default:
          ShowWindow(hwnd, SW_NORMAL);
          break;
    }
    SetWindowPos(0, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
    SetForegroundWindow(hwnd);
    // END Restore

    // Window has been found, don't create another one.
    return true;
  }

  return false;
}

Add the call to the previous method in CreateAndShow

bool Win32Window::CreateAndShow(const std::wstring& title,
                                const Point& origin,
                                const Size& size) {
if (SendAppLinkToInstance(title)) {
    return false;
}

...

Great!

Now you can register your own scheme.
On Windows, URL protocols are setup in the Windows registry.

This package won't do it for you (and will never sorry).

You can achieve it with url_protocol inside you app.

But... The most relevant solution is to include those registry modifications into your installer to allow the unregistration.

Mac OS

Add this XML chapter in your macos/Runner/Info.plist inside <plist version="1.0"><dict> chapter:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <!-- abstract name for this URL type (you can leave it blank) -->
        <string>sample_name</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <!-- your schemes -->
            <string>sample</string>
        </array>
    </dict>
</array>

Done!


AppLinks usage

final _appLinks = AppLinks();

// Get the initial/first link.
// This is useful when app was terminated (i.e. not started)
final uri = await _appLinks.getInitialAppLink();
// Do something (navigation, ...)

// Subscribe to further events when app is started.
// (Use stringLinkStream to get it as [String])
_linkSubscription = _appLinks.uriLinkStream.listen((uri) {
    // Do something (navigation, ...)
});

...

// Maybe later. Get the latest link.
final uri = await _appLinks.getLatestAppLink();

Android notes:

  • By default, flutter Activity is set with android:launchMode="singleTop". This is perfectly fine and expected, but this launches another instance of your app, specifically for the requested view.
    If you don't want this behaviour, you can set android:launchMode="singleInstance" in your AndroidManifest.xml and avoid another flutter warmup.

Tests

The following commands will help you to test links.

Android

adb shell am start
    -W -a android.intent.action.VIEW
    -d "<URI>" <PACKAGE>

For App Links, you can also test it from Android Studio: Documentation.

iOs

/usr/bin/xcrun simctl openurl booted "<URI>"
Changelog

3.3.0

  • feat: Triggering Firebase dynamic links for Android >= 12 (behaviour changes). (thanks to AdrienAudouard)

3.2.0

  • feat: Add macOS support.

3.1.0

  • feat: Add Windows support.

3.0.2

  • fix: iOS application callbacks do not return true anymore.

3.0.1

  • core: Improve Android code.

3.0.0

  • core: Breaking API changed to use stream instead of callback.
  • fix: Consistent behaviour between iOS & Android with (deffered) stream usage (for onAppLink vs. getInitialLink "duplicated" links).
  • fix: remove example splashscreen deprecation.

2.2.2

  • core: Add linter.
  • fix: Get rid of Android LocalBroadcastReceiver deprecation (removed dependency & import...).

2.2.1

  • fix: Duplicated iOS call when app is on terminated status.
  • fix: iOS application callback does not return true anymore.
  • fix: Get rid of Android LocalBroadcastReceiver deprecation.
  • core: Updated dependencies.

2.2.0

  • Add web support. (getInitialAppLink() only).

2.1.0

  • Breaking: String uri added on onAppLink for custom handling like uppercased uri.
  • Feat: getInitialAppLinkString and getLatestAppLinkString added to reflect the above change.

2.0.0+1

  • Minimal sample added (Thanks to @JamesCullum).

2.0.0

  • Add null safety support.

1.0.0

  • Same as 0.2.0.
  • No known issue. Bumping to 1.0 to be prepared for null safety version.

0.2.0

  • Add configurations in example.

0.1.0+2

  • Update README.md.

0.1.0+1

  • Add documentation.
  • Format dart source code.

0.1.0

  • Initial release.
  • Android App Links, Deep Links, iOs Universal Links and Custom URL schemes.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add 'app_links:3.3.0'
pubspec.yaml
name: app_links
description: Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler for Flutter (desktop included).
version: 3.3.0
homepage: https://github.com/llfbandit/app_links

environment:
  sdk: ">=2.12.0 <3.0.0"
  flutter: ">=2.0.0"

dependencies:
  flutter:
    sdk: flutter
  app_links_platform_interface: ^1.0.1
  app_links_web: ^1.0.0
  app_links_windows: ^1.0.0
  app_links_macos: ^1.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  # https://pub.dev/packages/lints
  lints: ^1.0.1

flutter:
  plugin:
    platforms:
      android:
        package: com.llfbandit.app_links
        pluginClass: AppLinksPlugin
      ios:
        pluginClass: AppLinksPlugin
      web:
        default_package: app_links_web
      windows:
        default_package: app_links_windows
      macos:
        default_package: app_links_macos

Version history

VersionPublishedArchiveSHA-256
0.1.0Cached · Upstream SHA-256 matchedDownload07891d9d…8285a8
0.1.0+1Cached · Upstream SHA-256 matchedDownload86542ee4…50d501
0.1.0+2Cached · Upstream SHA-256 matchedDownload2ec3d04c…2af9d4
0.2.0Cached · Upstream SHA-256 matchedDownloadbecd0893…97c3d0
1.0.0Cached · Upstream SHA-256 matchedDownload2c0b508b…c91682
2.0.0Cached · Upstream SHA-256 matchedDownloada3bc0cfb…9a8176
2.0.0+1Cached · Upstream SHA-256 matchedDownloadcf0bb213…342014
2.1.0Cached · Upstream SHA-256 matchedDownload8952ce08…a65c01
2.2.0Cached · Upstream SHA-256 matchedDownload02d5b116…dd18f7
2.2.1Cached · Upstream SHA-256 matchedDownload4af01185…c78234
2.2.2Cached · Upstream SHA-256 matchedDownloadde064ea9…db2f1c
3.0.0Cached · Upstream SHA-256 matchedDownloadfcf08826…f3bb35
3.0.1Cached · Upstream SHA-256 matchedDownloadbbe434aa…d35163
3.0.2Cached · Upstream SHA-256 matchedDownload24feda5b…787688
3.1.0Cached · Upstream SHA-256 matchedDownload7a28970b…8db7f2
3.2.0Cached · Upstream SHA-256 matchedDownloadcbf1dbb4…33ecfe
3.3.0Cached · Upstream SHA-256 matchedDownloadd1b2cf9a…e36a0d
3.4.0Cached · Upstream SHA-256 matchedDownloada669e117…da4df2
3.4.1Cached · Upstream SHA-256 matchedDownload0ae67296…0d1e8e
3.4.2Cached · Upstream SHA-256 matchedDownloadd572dcdf…c1b5e8
3.4.3Cached · Upstream SHA-256 matchedDownload16725e71…6a4cb6
3.4.4Cached · Upstream SHA-256 matchedDownloadf41abc50…80abd5
3.4.5Cached · Upstream SHA-256 matchedDownloadeb83c2b1…ef0dae
3.5.0-beta.1Cached · Upstream SHA-256 matchedDownloadb577f5af…703122
3.5.0-beta.2Cached · Upstream SHA-256 matchedDownload6604788c…0ac535
3.5.0-beta.3Cached · Upstream SHA-256 matchedDownload1e1e917e…e5cef8
3.5.0Cached · Upstream SHA-256 matchedDownload4e392b5e…74a3bb
3.5.1Cached · Upstream SHA-256 matchedDownload3ced568a…0cada4
4.0.0Cached · Upstream SHA-256 matchedDownloadfd7fc156…88bb5f
4.0.1Cached · Upstream SHA-256 matchedDownload42dc15ae…08c815
5.0.0Cached · Upstream SHA-256 matchedDownload0fd41f05…eeb121
6.0.0Cached · Upstream SHA-256 matchedDownloadf57cf388…ca3a9f
6.0.1Cached · Upstream SHA-256 matchedDownload1c2b9e9c…53d001
6.0.2Cached · Upstream SHA-256 matchedDownload8c6ef5ba…e736c9
6.1.0Cached · Upstream SHA-256 matchedDownloadc7b2c446…9a0cc1
6.1.1Cached · Upstream SHA-256 matchedDownload96e67781…5eb3db
6.1.2Cached · Upstream SHA-256 matchedDownload49117eef…9e7a14
6.1.3Cached · Upstream SHA-256 matchedDownloada9905d6a…c4f06b
6.1.4Cached · Upstream SHA-256 matchedDownloadae5f9a1b…70c4af
6.2.0Cached · Upstream SHA-256 matchedDownload4acba851…ceb0c7
6.2.1Cached · Upstream SHA-256 matchedDownloadf04c3ca9…305e21
6.3.0Cached · Upstream SHA-256 matchedDownload50437e59…e1c5ea
6.3.1Cached · Upstream SHA-256 matchedDownload7e058edb…93a491
6.3.2Cached · Upstream SHA-256 matchedDownloadad1a6d59…84dd99
6.3.3Cached · Upstream SHA-256 matchedDownload433df2e6…be7950
6.4.0Cached · Upstream SHA-256 matchedDownload85ed8fc1…bb54ba
6.4.1Cached · Upstream SHA-256 matchedDownload5f884475…cee3e8
7.0.0Cached · Upstream SHA-256 matchedDownload3462d9de…8a7abc
7.1.0Cached · Upstream SHA-256 matchedDownloada408901c…7a4e4f
7.1.1Cached · Upstream SHA-256 matchedDownloada350a5b3…483c18
7.1.2Cached · Upstream SHA-256 matchedDownload4ec328cd…7f1315
7.2.0Cached · Upstream SHA-256 matchedDownload9d3c82f6…780dbe
7.2.1Cached · Upstream SHA-256 matchedDownloadf8db46d2…1188ea
7.2.2Cached · Upstream SHA-256 matchedDownload08ba88bf…bc69c3

Dependencies

app_links_macos "^1.0.0"

app_links_platform_interface "^1.0.1"

app_links_web "^1.0.0"

app_links_windows "^1.0.0"

flutter { "sdk": "flutter" }