p-hatan/ mirror

pub repository

mirror.p-hatan.ir

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.ir
flutter pub add app_links
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.02020-11-26T17:21:15.583592ZDownload07891d9d2c85d1ce15745bd5e018b90924e89c43ad0d3f29983dd828c88285a8
0.1.0+12020-11-26T17:40:51.307309ZDownload86542ee42e6152d35264f0d3f87a08a9088615489ade05e29b33d85f6750d501
0.1.0+22020-11-26T19:08:30.370087ZDownload2ec3d04c172ad43e31d6ff3737d70b672f168f5c4345fafc318ce382532af9d4
0.2.02020-12-02T15:01:01.249049ZDownloadbecd089384b3581cd07acc14e375db251e0f8b344111217c527c5d5cce97c3d0
1.0.02021-02-13T12:45:17.509896ZDownload2c0b508b92dfab7ec0368efdead57684acc635dc3c2df9ac4f33dfe152c91682
2.0.02021-03-04T15:46:37.423728ZDownloada3bc0cfb0ef13e669cb3f01b592552f7685e5cc5d9a21da0f8622817ca9a8176
2.0.0+12021-04-15T19:07:17.535095ZDownloadcf0bb21377a55d0be49e64202cf78122b8e081cb087382d54d83d5a2bf342014
2.1.02021-05-07T08:13:15.806372ZDownload8952ce086fd9c1e6a4fdeeedfeae85ab82ccb6fd24c6fcfd16b84095b0a65c01
2.2.02021-06-13T15:34:35.203035ZDownload02d5b116c72782522133a5cf6edac4520b41041af29511e1caf1e3b055dd18f7
2.2.12022-02-18T13:48:35.364711ZDownload4af01185a7a3ca1a36b4f576acd6e54dd5061087e3c3305999b36c148bc78234
2.2.22022-02-25T16:35:19.983875ZDownloadde064ea9dca1c590a414662caf65a48a32dbeb2d7a24365baa74f1ac84db2f1c
3.0.02022-02-27T17:04:13.430661ZDownloadfcf08826775e58bf23073f59f5ad3ccd67f097d3e6135e00d0f7b7e2abf3bb35
3.0.12022-02-28T08:06:32.719242ZDownloadbbe434aa035165cf654490ecfb4d52b0b4407b4f0dd8d392df0d5d0a8bd35163
3.0.22022-04-25T16:47:14.883349ZDownload24feda5b64e5fdc3e02f52c4ede446bcd838b6a3c3dc120eae753dc348787688
3.1.02022-04-28T14:37:02.480899ZDownload7a28970b667c02d2ed950ea11a2ddb116f023c52e0ec85a4fb1256ce008db7f2
3.2.02022-04-29T10:07:51.675207ZDownloadcbf1dbb4d39f2b7c36f5751ee9ba2dac03f4bb2e7309f590a856a9302333ecfe
3.3.02022-09-28T18:51:01.141895ZDownloadd1b2cf9ad5568cc5b9036cb3f8c42705b4ada26c4ef57de75323186eafe36a0d
3.4.02022-12-12T12:54:46.207118ZDownloada669e117df216208daa42266366af59bf2d69fb0780d081715f7e064a1da4df2
3.4.12022-12-14T14:54:50.554417ZDownload0ae672961f4fdc1424c6a5d11b7a4e3791bb07a9332f26c8314546365a0d1e8e
3.4.22023-02-23T17:06:20.530984ZDownloadd572dcdff49c4cfcfa6f315e2683e518ec6eb54e084d01e51d9631a4dcc1b5e8
3.4.32023-05-22T09:12:41.325350ZDownload16725e716afd0634a5441654b1dda2b6c5557aa230884b5e1f41a5aa546a4cb6
3.4.42023-09-23T23:05:10.166833ZDownloadf41abc506363dee2515db66155dbb1c247328c683ba925acb7d625cf6780abd5
3.4.52023-09-23T23:43:06.723483ZDownloadeb83c2b15b78a66db04e95132678e910fcdb8dc3a9b0aed0c138f50b2bef0dae
3.5.0-beta.12023-11-30T11:20:15.542483ZDownloadb577f5afe4121a778056fc02eeea7ac8eef0ef4dfac9e60d263e037a3f703122
3.5.0-beta.22023-11-30T12:27:13.388233ZDownload6604788ccddaa18502aa1adffe44c253a5f30ac51e5fce7f41d58da22f0ac535
3.5.0-beta.32023-12-11T13:47:41.323986ZDownload1e1e917ed211d867e69c125ead63f0cb2c8dc5cf54b8a58ad6bf27647ce5cef8
3.5.02023-12-14T13:48:40.083051ZDownload4e392b5eba997df356ca6021f28431ce1cfeb16758699553a94b13add874a3bb
3.5.12024-03-05T13:21:45.202807ZDownload3ced568a5d9e309e99af71285666f1f3117bddd0bd5b3317979dccc1a40cada4
4.0.02024-03-13T20:50:11.390495ZDownloadfd7fc1569870b4b0d90d17a9f36661a6ff92400fecb6e4adab4abe0f0488bb5f
4.0.12024-03-19T12:44:46.766102ZDownload42dc15aecf2618ace4ffb74a2e58a50e45cd1b9f2c17c8f0cafe4c297f08c815
5.0.02024-04-25T14:04:31.283609ZDownload0fd41f0501f131d931251e0942ac63d6216096a0052aeca037915c2c1deeb121
6.0.02024-05-04T20:25:55.234774ZDownloadf57cf3889e11f927fbc92ec1e74079614ff652179d0be06d34f2488873ca3a9f
6.0.12024-05-05T12:48:35.165345ZDownload1c2b9e9c56d80d17610bcbd111b37187875c5d0ded8654caa1bda14ea753d001
6.0.22024-05-13T13:30:30.699014ZDownload8c6ef5ba9e26b720d4c9073826befb87df2ab5e7a81c22b6c3145080b5e736c9
6.1.02024-05-21T13:14:41.919625ZDownloadc7b2c4466992ed824da0d994a293670b704c13ec9f1f4f3c8c4b4fc2869a0cc1
6.1.12024-05-21T13:18:32.027245ZDownload96e677810b83707ff5e10fac11e4839daa0ea4e0123c35864c092699165eb3db
6.1.22024-06-25T14:12:27.281771ZDownload49117eefee46a97cf5037bb5baacc882556b22e631e18087b0a18b29379e7a14
6.1.32024-06-25T20:25:54.292175ZDownloada9905d6a60e814503fabc7523a9ed161b812d7ca69c99ad8ceea14279dc4f06b
6.1.42024-07-03T16:03:46.851547ZDownloadae5f9a1b7d40d26178f605414be81ed4260350b4fae8259fe5ca4f89fe70c4af
6.2.02024-08-09T20:36:31.752963ZDownload4acba851087b25136e8f6e32a53bd4536eb3bec69947ddb66e7b9a5792ceb0c7
6.2.12024-08-21T20:32:27.436722ZDownloadf04c3ca96426baba784c736a201926bd4145524c36a1b38942a351b033305e21
6.3.02024-08-24T17:46:13.448682ZDownload50437e5916e6f56c1ca53e967cbfd6d53b3451465b41eef05ba1533bf1e1c5ea
6.3.12024-08-31T13:08:09.678260ZDownload7e058edbc78bd40b6a8227941b955f38320a4e799bc0983c8146bda41593a491
6.3.22024-09-05T15:46:09.276658ZDownloadad1a6d598e7e39b46a34f746f9a8b011ee147e4c275d407fa457e7a62f84dd99
6.3.32024-12-12T12:54:18.099238ZDownload433df2e61b10519407475d7f69e470789d23d593f28224c38ba1068597be7950
6.4.02025-02-18T18:27:06.347969ZDownload85ed8fc1d25a76475914fff28cc994653bd900bc2c26e4b57a49e097febb54ba
6.4.12025-08-14T10:08:20.009276ZDownload5f88447519add627fe1cbcab4fd1da3d4fed15b9baf29f28b22535c95ecee3e8
7.0.02025-11-17T12:30:46.082817ZDownload3462d9defc61565fde4944858b59bec5be2b9d5b05f20aed190adb3ad08a7abc
7.1.02026-05-26T16:54:01.747342ZDownloada408901c5d33e2b5f33064e5db849ce20176e46c5cddb2bf518a5c4c9e7a4e4f
7.1.12026-05-27T11:34:59.470595ZDownloada350a5b37579b7227aaf9a59c07114617cd4283852e193f743b2b3d2d7483c18
7.1.22026-06-11T08:44:25.717971ZDownload4ec328cd9fd51fd0e7eb8870a9612c1fde0f091901932238c4f4e60b5f7f1315
7.2.02026-06-23T20:33:13.191601ZDownload9d3c82f634c7f5b5c752f7ee46b67724246043f5e1d5fc1b433dd5b38d780dbe
7.2.12026-07-09T13:35:28.512394ZDownloadf8db46d2ea9ff6f3a37191a7fd5b7813da1253ace8c32c1b9eadace41d1188ea
7.2.22026-10-06T13:54:36.730853ZDownload08ba88bf19d9edea33130cb71c8ced2cb982b4e00b82efef4a434d1357bc69c3

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" }