Reputation: 2267
Is it possible to implement this behavior cross-platform in flutter:
As far as I know, this was possible to do using Firebase Dynamic Links
, but this service will be closed.
Android has the ability to pass a link to the Play Store along with a referrer parameter, which can then be read in the application after installation, but this does not cover all the cases I described above.
Is there a (preferably free) alternative to Firebase Dynamic Links
?
Upvotes: 1
Views: 113
Reputation: 540
You can use flutter_branch_sdk for deep links. Create an account on Branch.io and create links from dashboard and also from app. Follow its documentation for better use.
Read deep link
To listen to the clicks on the deep link and retrieve the data it is necessary to add the code below:
StreamSubscription<Map> streamSubscription = FlutterBranchSdk.listSession().listen((data) {
if (data.containsKey("+clicked_branch_link") &&
data["+clicked_branch_link"] == true) {
//Link clicked. Add logic to get link data
print('Custom string: ${data["custom_string"]}');
}
}, onError: (error) {
print('listSession error: ${error.toString()}');
});
Retrieve Install (Install Only) Parameters
If you ever want to access the original session params (the parameters passed in for the first install event only), you can use this line. This is useful if you only want to reward users who newly installed the app from a referral link.
Map<dynamic, dynamic> params = await FlutterBranchSdk.getFirstReferringParams();
Create content reference (Branch Universal Object)
The Branch Universal Object encapsulates the thing you want to share.
BranchUniversalObject buo = BranchUniversalObject(
canonicalIdentifier: 'flutter/branch',
//canonicalUrl: '',
title: 'Flutter Branch Plugin',
imageUrl: 'https://raw.githubusercontent.com/RodrigoSMarques/flutter_branch_sdk/master/assets/branch_logo_qrcode.jpeg',
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']),
);
Upvotes: 1