Flutter SDK Full Reference
All available methods of Branch for your Flutter app.
initSession
方法 | 描述 |
---|---|
Initiates a session with the Branch API through a listener. |
用法示例
streamSubscription = FlutterBranchSdk.initSession().listen((data) {
print('listenDynamicLinks - DeepLink Data: $data');
controllerData.sink.add((data.toString()));
if (data.containsKey('+clicked_branch_link') &&
data['+clicked_branch_link'] == true) {
print(
'------------------------------------Link clicked----------------------------------------------');
print('Custom string: ${data['custom_string']}');
print('Custom number: ${data['custom_number']}');
print('Custom bool: ${data['custom_bool']}');
print('Custom list number: ${data['custom_list_number']}');
print(
'------------------------------------------------------------------------------------------------');
showSnackBar(
context: context,
message: 'Link clicked: Custom string - ${data['custom_string']}',
duration: 10);
}
}, onError: (error) {
PlatformException platformException = error as PlatformException;
print(
'InitSession error: ${platformException.code} - ${platformException.message}');
controllerInitSession.add(
'InitSession error: ${platformException.code} - ${platformException.message}');
});
validateSDKIntegration
方法 | 描述 |
---|---|
Use the SDK integration validator to check that you've added the Branch SDK and handle deep links correctly when you first integrate Branch into your app. Validates the following:
|
Example Usage:
FlutterBranchSdk.validateSDKIntegration();
setRequestMetadata
方法 | 描述 |
---|---|
Sets specific key/value pairs to all requests. This is required for integrating with specific partners like Adobe Analytics, Amplitude, etc. Partner keys can be found in the partner-specific guides. |
Argument | 类型 | 描述 |
---|---|---|
|
| The partner key. Ex. |
|
| The value of the partner key |
用法示例
FlutterBranchSdk.setRequestMetadata(requestMetadataKey, requestMetadataValue);
setIdentity
方法 | 描述 |
---|---|
Sets the identity of a user (ID, UUID, etc) for events, deep links, and referrals. Use this method when the user logs into their account in your app. See PII Best Practices for details. |
Argument | 类型 | 描述 |
---|---|---|
|
| The unique ID of the user |
用法示例
FlutterBranchSdk.setIdentity('user1234567890');
isUserIdentified
方法 | 描述 |
---|---|
Indicates whether or not this user has a custom identity specified for them. Note that this is independent of installs. If you call the This includes persisting through uninstalls, as device ID is tracked. |
用法示例
bool isUserIdentified = await FlutterBranchSdk.isUserIdentified();
logout
方法 | 描述 |
---|---|
Clears the identity set from the |
用法示例
FlutterBranchSdk.logout();
getLatestReferringParams
方法 | 描述 |
---|---|
Returns the last parameters associated with the link that referred the user to the current app session. |
用法示例
Map<dynamic, dynamic> params = await FlutterBranchSdk.getLatestReferringParams();
getFirstReferringParams
方法 | 描述 |
---|---|
Returns the first parameters associated with the link that referred the user. Consider this as the parameters used to retrieve the details from the user's first app session. |
用法示例
ap<dynamic, dynamic> params = await FlutterBranchSdk.getFirstReferringParams();
disableTracking
方法 | 描述 |
---|---|
| If you need to comply with a user's request to not be tracked for GDPR purposes, or otherwise determine that a user should not be tracked, utilize this method to prevent Branch from sending network requests. This setting can also be enabled across all users for a particular link or across your Branch Links. |
Argument | 类型 | 描述 |
---|---|---|
|
| If set to |
用法示例
FlutterBranchSdk.disableTracking(true);
getShortUrl
方法 | 描述 |
---|---|
Generates a Branch Short Link used for deep linking an attribution. |
Argument | 类型 | 描述 |
---|---|---|
|
| The Universal Object used to define content within your app. |
|
| The analytics properties associated with the link you are about to generate. |
用法示例
BranchUniversalObject buo = BranchUniversalObject(
canonicalIdentifier: 'flutter/branch',
//canonicalUrl: '',
title: 'Flutter Branch Plugin',
imageUrl: 'https://flutter.dev/assets/flutter-lockup-4cb0ee072ab312e59784d9fbf4fb7ad42688a7fdaea1270ccf6bbf4f34b7e03f.svg',
contentDescription: 'Flutter Branch Description',
keywords: ['Plugin', 'Branch', 'Flutter'],
publiclyIndex: true,
locallyIndex: true,
contentMetadata: BranchContentMetaData()..addCustomMetadata('custom_string', 'abc')
..addCustomMetadata('custom_number', 12345)
..addCustomMetadata('custom_bool', true)
..addCustomMetadata('custom_list_number', [1,2,3,4,5 ])
..addCustomMetadata('custom_list_string', ['a', 'b', 'c']),
);
BranchLinkProperties lp = BranchLinkProperties(
//alias: 'flutterplugin', //define link url,
channel: 'facebook',
feature: 'sharing',
stage: 'new share',
tags: ['one', 'two', 'three']
);
lp.addControlParam('url', 'http://www.google.com');
lp.addControlParam('url2', 'http://flutter.dev');
BranchResponse response =
await FlutterBranchSdk.getShortUrl(buo: buo, linkProperties: lp);
if (response.success) {
print('Link generated: ${response.result}');
} else {
print('Error : ${response.errorCode} - ${response.errorMessage}');
}
showShareSheet
方法 | 描述 |
---|---|
Displays a share sheet to prompt the user to share to an external platform (ex. messaging) |
Argument | 类型 | 描述 |
---|---|---|
|
| The Universal Object used to define content within your app. |
|
| The analytics properties associated with the link you are about to generate. |
|
| The body of the message in your share sheet. |
|
| The message title of the share sheet. |
|
| The sharing title of the share sheet. |
用法示例
BranchResponse response = await FlutterBranchSdk.showShareSheet(
buo: buo,
linkProperties: lp,
messageText: 'My Share text',
androidMessageTitle: 'My Message Title',
androidSharingTitle: 'My Share with');
if (response.success) {
print('showShareSheet Sucess');
} else {
print('Error : ${response.errorCode} - ${response.errorMessage}');
}
getQRCode
方法 | 描述 |
---|---|
Method getQRCodeAsData returns the QR code as Uint8List. Can be stored in a file or converted to image. | |
Method getQRCodeAsImage returns the QR code as a Image. |
Argument | 类型 | 描述 |
---|---|---|
|
| Color name or Hex color value |
|
| Color name or Hex color value of the background of the QR code itself. |
|
| The number of pixels you want for the margin. Min 1px. Max 20px. |
|
| Output size of QR Code image. Min 300px. Max 2000px. (Only applicable to JPEG/PNG) |
|
| JPEG, PNG |
|
| URL to the image you want as a center logo e.g. https://raw.githubusercontent.com/RodrigoSMarques/flutter_branch_sdk/master/assets/branch_logo_qrcode.jpeg |
用法示例
BranchResponse responseQrCodeImage = await FlutterBranchSdk.getQRCodeAsImage(
buo: buo!,
linkProperties: lp,
qrCode: BranchQrCode(primaryColor: Colors.black,
//primaryColor: const Color(0xff443a49), //Hex colors
centerLogoUrl: imageURL,
backgroundColor: Colors.white,
imageFormat: BranchImageFormat.PNG));
if (response.success) {
print('QrCode Success');
showQrCode(this.context, responseQrCodeImage.result);
/*
Image(image: responseQrCodeImage.result,
height: 250,
width: 250,),
*/
} else {
print('Error : ${response.errorCode} - ${response.errorMessage}');
trackEvents
默认情况下,Branch SDK 会自动(不需额外设置)追踪点击,打开,安装,重新安装和展示。
Please refer to our Event Tracking Docs for more information and examples:
registerView
方法 | 描述 |
---|---|
Mark the content referred to by this object as viewed. This will increment the view count of the contents referred by this object. |
Argument | 类型 | 描述 |
---|---|---|
|
| The Universal Object used to define content within your app. |
用法示例
FlutterBranchSdk.registerView(buo: buo);
listOnSearch
方法 | 描述 |
---|---|
For Android:
For iOS:
|
Argument | 类型 | 描述 |
---|---|---|
|
| The Universal Object used to define content within your app. |
|
| The analytics properties associated with the link you are about to generate. |
用法示例
bool success = await FlutterBranchSdk.listOnSearch(buo: buo);
print(success);
removeFromSearch
方法 | 描述 |
---|---|
For Android:
For iOS:
|
Argument | 类型 | 描述 |
---|---|---|
|
| The Universal Object used to define content within your app. |
|
| The analytics properties associated with the link you are about to generate. |
用法示例
bool success = await FlutterBranchSdk.removeFromSearch(buo: buo);
print('Remove sucess: $success');
setIOSSKAdNetworkMaxTime
方法 | 描述 |
---|---|
Sets the time window for SKAdNetwork callout in hours. iOS ONLY. By default, Branch limits calls to SKAdNetwork to within 72 hours after first install. |
Argument | 类型 | 描述 |
---|---|---|
|
| Time window in hours. |
用法示例
FlutterBranchSdk.setIOSSKAdNetworkMaxTime(24);
requestTrackingAuthorization
方法 | 描述 |
---|---|
Requests AppTracking Authorization and returns AppTrackingStatus. iOS ONLY |
用法示例
AppTrackingStatus status = await FlutterBranchSdk.requestTrackingAuthorization();
print(status);
getTrackingAuthorizationStatus
方法 | 描述 |
---|---|
Returns AppTrackingStatus. iOS ONLY |
用法示例
AppTrackingStatus status = await FlutterBranchSdk.getTrackingAuthorizationStatus();
print(status);
getAdvertisingIdentifier
方法 | 描述 |
---|---|
Returns the advertising identifier. iOS ONLY |
用法示例
String status = await FlutterBranchSdk.getAdvertisingIdentifier();
print(status);
Updated 3 months ago