Referral Link / Code Sharing in Flutter App

94 views Asked by At

I want to build a module for Sharing Referral Link (https://flutterfirebase.page.link/ref_code=ABC123). Now that I have created the Link, I want to get the REFERRAL CODE i.e. ABC123 from that Link and paste it on let's say, the Sign Up Page where there is an option of adding a Referral Code.

 void handleDynamicLink() async {
final PendingDynamicLinkData? data = await FirebaseDynamicLinks.instance.getInitialLink();

if (data?.link != null) {
  Uri uri = Uri.parse('https://herody.page.link/referral_code/?code=id');
  final Uri? deepLink = data?.link;
  final referralCode = uri.queryParameters['code='].toString();
  final refCodeTest = deepLink!.queryParameters['id'].toString();


  if (referralCode != null) {
    referralCodeController.text = referralCode;
    FluroRouter.appRouter.navigateTo(context,'/referral_code/$referralCode');
    print(referralCode);
    print(refCodeTest);
  }
}
FirebaseDynamicLinks.instance.onLink.listen((PendingDynamicLinkData? dynamicLink) async {
  final Uri Dlinks = dynamicLink?.link ?? Uri.parse('https://herody.page.link/referral_code/?code=');
  final referralCode = Dlinks.queryParameters['code'].toString();

  if(referralCode != null) {
    referralCodeController.text = referralCode;

  }
});

I did use TextEditingController for capturing the referral Code, but it seems it is not doing that. Can someone please let me know what is the solution.

0

There are 0 answers