Flutter SDK Reference
This page is a comprehensive API reference for the OpenLynk Flutter SDK. For a step-by-step integration walkthrough, see the Flutter Integration Tutorial.
Installation
Add the SDK to your pubspec.yaml:
dependencies:
openlynk_sdk:
git:
url: https://github.com/openlynk-sdk/openlynk-flutter.git
ref: main
Run flutter pub get after adding the dependency.
The SDK depends on the following packages (resolved automatically):
httpshared_preferencesdevice_info_plusapp_links
OpenlynkSDK Constructor
OpenlynkSDK({
required String appId,
required String apiKey,
String baseURL = 'https://openlynk.io',
OpenlynkSDKConfig config = const OpenlynkSDKConfig(),
})
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
appId | String | Yes | — | Your app ID from the OpenLynk dashboard |
apiKey | String | Yes | — | Your API key (format: ol_...) |
baseURL | String | No | https://openlynk.io | API base URL |
config | OpenlynkSDKConfig | No | OpenlynkSDKConfig() | SDK configuration options |
Methods
| Method | Returns | Description |
|---|---|---|
init() | Future<void> | Start listeners, restore pending links, process cold-start link |
dispose() | void | Stop the deep link listener |
createLink({destination, metadata}) | Future<CreatedLink> | Create a shareable deep link |
parseDeepLink(Uri uri) | Future<ParsedDeepLink?> | Parse a deep link URL manually |
getLinkBySlug({slug, hostname}) | Future<LinkDetails> | Fetch link details by slug |
restorePendingLinks({userEmail}) | Future<List<RestoredLink>> | Restore deferred links by email |
restorePendingLinksForAnonymous() | Future<List<RestoredLink>> | Restore deferred links using device fingerprint |
registerPushToken(token, {userEmail}) | Future<void> | Register an FCM token for push notifications |
handlePushPayload(data) | Future<void> | Process push notification payload data |
OpenlynkSDKConfig
const OpenlynkSDKConfig({
bool autoRestoreOnInit = true,
Future<String?> Function()? userEmailProvider,
void Function(List<RestoredLink>)? onRestoredLinks,
void Function(ParsedDeepLink)? onDeepLink,
})
| Property | Type | Default | Description |
|---|---|---|---|
autoRestoreOnInit | bool | true | Automatically restore pending links when init() is called |
userEmailProvider | Future<String?> Function()? | null | Async function that returns the current user's email for deferred deep linking |
onRestoredLinks | void Function(List<RestoredLink>)? | null | Callback invoked when deferred links are restored |
onDeepLink | void Function(ParsedDeepLink)? | null | Callback invoked when a deep link opens the app |
What init() Does
Calling init() performs the following steps in order:
- Install heartbeat — sends a heartbeat to the OpenLynk API, reporting that the SDK is installed on this device. Throttled server-side to once per 24 hours.
- Restore pending links — if
autoRestoreOnInitistrue, callsrestorePendingLinks()orrestorePendingLinksForAnonymous()depending on whetheruserEmailProviderreturns an email. Fires theonRestoredLinkscallback with any matches. - Start link listener — begins listening for incoming deep links using the
app_linkspackage. When a link arrives, it is parsed and theonDeepLinkcallback fires. - Process cold-start link — checks if the app was launched via a deep link (cold start). If so, parses the link and fires
onDeepLink.
Call init() as early as possible in your app lifecycle, typically in your root widget's initState().
Callback-Based Alternatives
For cases where you prefer callbacks over async/await, the SDK provides callback-based versions of key methods:
| Async Method | Callback Alternative |
|---|---|
createLink() | createLinkWithCallback(destination, metadata, callback) |
restorePendingLinks() | restorePendingLinksWithCallback(userEmail, callback) |
restorePendingLinksForAnonymous() | restorePendingLinksForAnonymousWithCallback(callback) |
Error Handling
All async methods throw exceptions on failure. Wrap calls in try-catch:
try {
final link = await sdk.createLink(
destination: '/product/123',
metadata: {'campaign': 'summer'},
);
} catch (e) {
print('Failed to create link: $e');
}
Common errors:
| Error | Cause |
|---|---|
| Network error | Device is offline or API is unreachable |
| Invalid app ID | The appId does not match any app in OpenLynk |
| Invalid destination | The destination parameter is empty or malformed |
| Rate limit exceeded | Too many API calls in a short period (HTTP 429) |
Platform Setup
The Flutter SDK uses Universal Links on iOS and App Links on Android. You must configure these in your native project:
- iOS: See iOS Universal Links Guide
- Android: See Android App Links Guide
Deep links will not work without completing platform-specific setup. The SDK can create and restore links without it, but incoming link handling requires Universal Links or App Links to be configured.
Related Pages
- Data Types Reference — full field-level documentation for
CreatedLink,ParsedDeepLink,RestoredLink, andLinkDetails - Flutter Integration Tutorial — step-by-step guide to integrating the SDK
What's Next?
- Complete your platform setup so deep links open your app
- Learn how to handle deep links in your Flutter app
- Implement deferred deep linking for users who install after clicking a link