Skip to main content

Flutter Usage

Listen for links, read link data, handle deferred deep links and use the iOS paste widgets.

This documentation covers apliko_link 0.1.0 for Flutter.

Central Listener

Register one central listener at startup. It receives the one-time links (the link that started the app, a deferred link) and every runtime link. Screens that mount later read AplikoLink.getCurrentLink().

dart
void main() {
  WidgetsFlutterBinding.ensureInitialized();

  AplikoLink.init('cl_live_…');
  AplikoLink.addListener((url, data, meta) {
    router.open(url, data);
  });

  runApp(const MyApp());
}

One-time links go to a single listener because they start once-per-open actions such as navigation, onboarding or attribution. Two listeners acting on one link would navigate twice. See How Links Are Delivered.

Link source

The third argument tells you how the link arrived:

meta.sourceMeaning
LinkSource.initialThe link that started the app.
LinkSource.runtimeA link opened while the app was running.
LinkSource.deferredThe link tapped before installing, delivered on first launch (on Android possibly a later launch, see Deferred Links).

Listening From a Widget

In a widget that listens for its own lifetime, register once in initState and remove the listener in dispose. Do not register in build or didUpdateWidget: a listener that re-registers moves to the back of the line, and a one-time link then goes to someone else.

dart
class _ScreenState extends State<Screen> {
  Unsubscribe? _stop;

  
  void initState() {
    super.initState();
    _stop = AplikoLink.addListener((url, data, meta) => widget.onLink(url));
  }

  
  void dispose() {
    _stop?.call();
    super.dispose();
  }
}

Reading the current link

dart
final CurrentLink? link = AplikoLink.getCurrentLink(); // url, data, source
final String? url = AplikoLink.getCurrentUrl();

// Takes the one-time launch link, so listeners will not get it:
final String? initial = await AplikoLink.getInitialUrlAsync();

getCurrentLink() and getCurrentUrl() are never used up. getInitialUrl() returns null until startup has finished, so prefer getInitialUrlAsync().

Link data

dart
final Map<String, dynamic> data =
    await AplikoLink.getDataForUrl('https://acme.nvgt.link/abc123');

For an Apliko link the SDK loads the link's data from Apliko with your client key, always over HTTPS, even for an http:// link, and returns it exactly as you set it up for the link. Anything that is not an Apliko link resolves to {}, and the key is never sent to any other host. The method never fails: if the link data can't be loaded, it resolves to {}, for example when the device is offline. See Troubleshooting if you get {} for an Apliko link.

iOS Paste Widgets

Opt in, then place the host once at the root of your app:

dart
AplikoLink.init('cl_live_…', enableDeferred: const EnableDeferred(ios: true));

runApp(
  WidgetsApp(
    // …
    builder: (context, child) => AplikoPasteHost(child: child),
  ),
);

The host opens by itself on the first launch of a fresh install that was not opened by a link, when iOS says a link is on the clipboard. This is a silent check; the clipboard is not read. It shows a title, a message, Apple's own Paste button and "Not now". When the user pastes an Apliko link, it is delivered to your listener as deferred, every paste UI disappears, and the clipboard is cleared if nothing was copied since.

AplikoPasteHostDefaultMeaning
child—Your app; the host draws over it.
modeAplikoPasteMode.automanual opens only through AplikoPaste.show() or the trigger.
presentationfloatingA floating card or a bottom sheet.
positionbottomFloating only: top or bottom.
title, message, dismissLabel"Pick up where you left off", "Paste the link you copied to open it here.", "Not now"An empty message is left out.
triggernoneA chip shown while there is something to offer and the host is closed: AplikoPasteTrigger(label: …, decoration: …, textStyle: …); only label is required.
containerDecoration, titleStyle, messageStyle, dismissStyle—Look. Text styles are merged over the defaults.
backdropColorColor(0x5C000000)Sheet only.
pasteButton—AplikoPasteButtonOptions for the button inside.
onLink, onInvalidContent, onDismiss—Callbacks. After onLink the host has closed; after onInvalidContent (something else was pasted) the host stays open.

AplikoPasteButton is Apple's button on its own, for your own layout. Like the host, it renders nothing unless there is a paste offer right now: the first launch of a fresh install that was not opened by a link, with EnableDeferred(ios: true), on iOS 16 or later, while iOS reports a link on the clipboard. Its text, font and icon come from iOS.

AplikoPasteButton / AplikoPasteButtonOptionsDefaultMeaning
displayModeiconAndLabelAplikoPasteDisplayMode: iconAndLabel, iconOnly or labelOnly.
cornerStylecapsuleAplikoPasteCornerStyle: capsule, large, medium, small or fixed.
backgroundColor, foregroundColoriOS defaultColors.
height48iOS draws the button into this height.
widthas wide as its parent allowsButton only.
onLink, onInvalidContent—Button only. An Apliko link was accepted, or something else was pasted.

AplikoPaste.show() and AplikoPaste.hide() open and close every mounted host. show() also does nothing without an offer: the host still shows nothing.

All paste UI renders nothing on Android, web, desktop, iOS below 16, without the opt-in, and after a link was pasted.

By default the Apliko link page copies the full link on the user's tap before it opens the App Store, and on Android opens Google Play with referrer=<full link>. Only your own store links or landing pages must carry the full Apliko link themselves (copied before the App Store, or as the Play referrer), otherwise there is nothing to deliver. See your project in the Hub.

Platform Notes

Android: Back, Recents and cached engines

The userResult
taps a link while the app is in frontDelivered once, runtime
leaves with Home, comes backNothing
leaves with Back, taps a linkDelivered once: initial with a default FlutterActivity, runtime with a cached or shared engine
leaves with Back, opens the app from the launcher or RecentsNothing
leaves with Home, Android ends the process, reopens from RecentsNothing
changes a setting that makes Android re-create the ActivityNothing

Web

  • The page URL is delivered once as the initial link.
  • webRuntimeLinks: true also reports Back/Forward and #fragment changes as runtime links, one per change. Off by default.
  • In an installed PWA, links handed to the open window are runtime links.