Flutter Dart SDK
AvailableCurrent SDK flow for Flutter apps using Dart — import, initialize, deep links, analytics, properties, and error handling.
Import the SDK
import 'package:navi_link/navi_link.dart';
Initialize the SDK
Initialize the SDK once when your app starts, before calling any SDK services.
await SdkInitializer.instance.initialize(
SdkConfig(
organizationId: '', // Get from the developer portal
projectId: '',
applicationId: '',
appToken: '',
),
);
Permissions
final permissions = SdkInitializer.instance.allowedFunctions;
print(permissions);
| Permission | Services |
|---|---|
deeplink | DeepLinkService |
navilytic | AnalyticsService, PropertiesService |
Deep Link Usage
Use DeepLinkService for deep link features. These methods require the backend permission deeplink.
Create a Link
Creates a link from an SDK configuration.
final response = await DeepLinkService.instance.createLink(
navilinkId: '*********', // Get from the developer portal
parameters: {
'product_id': 'prod_123',
'utm_source': 'facebook',
'campaign': 'summer_sale',
},
);
if (response.success) {
print(response.appSchemeUrl);
print(response.fallbackUrl);
} else {
print(response.errorMessage);
}
Generate a Deep Link
Generates a deep link URL, app scheme URL, and fallback URL for an SDK configuration.
final response = await DeepLinkService.instance.generateDeepLink(
navilinkId: '',
parameters: {
'product_id': 'prod_123',
},
);
if (response.success) {
print(response.deepLinkUrl);
print(response.appSchemeUrl);
print(response.fallbackUrl);
} else {
print(response.errorMessage);
}
Get Link Details
final response = await DeepLinkService.instance.getNavilink(
navilinkId: '',
);
if (response.success) {
print(response.navilinkId);
print(response.screenRoute);
print(response.name);
print(response.description);
print(response.applicationId);
print(response.appScheme);
} else {
print(response.errorMessage);
}
Analytics Usage
Use AnalyticsService to track events and analytics data. This requires the navilytic permission.
final response = await AnalyticsService.instance.trackCustomEvent(
eventName: 'purchase',
customParameters: {
'user_id': 'user_12345',
'product_id': 'prod_123',
'amount': '49.99',
'currency': 'USD',
},
);
if (response.success) {
print(response.eventId);
} else {
print(response.errorMessage);
}
Standard event names: app_open, page_view, add_to_cart, purchase, search, signup.
Properties Usage
For client apps, PropertiesService is usually simpler because it accepts a Dart map.
Set Global Navilytic Properties
final response = await PropertiesService.instance.setNavilyticProperties({
'app_version': '1.2.3',
'environment': 'production',
'device_model': 'iPhone 14',
'platform': 'ios',
});
Set Custom User Properties
final response = await PropertiesService.instance.setUserProperties({
'user_id': 'user_12345',
'name': 'Peter Parker',
'email': 'peter@gmail.com',
'subscription': 'premium',
'country': 'US',
'language': 'en',
});
Error Handling
try {
final response = await AnalyticsService.instance.trackCustomEvent(
eventName: 'signup',
customParameters: {
'method': 'email',
},
);
print(response.eventId);
} on SdkException catch (e) {
print(e.code);
print(e.message);
} catch (e) {
print(e);
}
Error codes: SDK_NOT_INITIALIZED, SDK_ALREADY_INITIALIZING, PERMISSION_DENIED, INVALID_CONFIG, AUTH_FAILED, NETWORK_ERROR, VALIDATION_ERROR.
Full Example
import 'package:flutter/material.dart';
import 'package:navi_link/navi_link.dart';
Future<void> setupNaviLink() async {
await SdkInitializer.instance.initialize(
SdkConfig(
organizationId: '',
projectId: '',
applicationId: '',
appToken: '',
),
);
await PropertiesService.instance.setUserProperties({
'user_id': 'user_12345',
'subscription': 'premium',
});
await AnalyticsService.instance.trackCustomEvent(
eventName: 'app_open',
customParameters: {
'source': 'organic',
},
);
}
Future<void> openCampaignLink() async {
final response = await DeepLinkService.instance.generateDeepLink(
navilinkId: '',
parameters: {
'product_id': 'prod_123',
},
);
if (response.success) {
print(response.deepLinkUrl);
print(response.appSchemeUrl);
print(response.fallbackUrl);
} else {
print(response.errorMessage);
}
}
Reset the SDK
Reset the SDK when logging out, switching accounts, or clearing the current SDK session.
await SdkInitializer.instance.reset();
