Flutter Referral Using Dynamic Links

Dynamic Links :

Flutter dynamic links, we have already seen the implementation of dynamic links in our previous tutorial and in this part of the tutorial we will be dealing with referral system implementation.

Referral system is the most important part of the popular e-commerce apps and we will be seeing how we can design this in our flutter app.

In this tutorial we are trying to send few parameters included through a link so here is the link which i have created https://onesignalpush.page.link/amplifyabhii

 

Dynamic Links Video Tutorial :

In this part of the tutorial i will be providing the detailed implementation and explanation through this tutorial.

 

pubspec.yaml :

Add firebase core and firebase dynamic links to your project and update to the latest version.

dependencies:
  flutter:
    sdk: flutter

  firebase_core: ^2.22.0
  firebase_dynamic_links: ^5.4.4

 

main.dart :

I have provided the complete code for the referral system implementation.

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';


void main() async
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  var initialLink = await FirebaseDynamicLinks.instance.getInitialLink();
  handleLink(initialLink);

  FirebaseDynamicLinks.instance.onLink.listen((event) async 
    handleLink(event);
  );

  runApp(MyApp());


class MyApp extends StatefulWidget 
  const MyApp(super.key);

  @override
  State<MyApp> createState() => _MyAppState();


class _MyAppState extends State<MyApp> 
  @override
  Widget build(BuildContext context) 
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("Firebase Referral"),),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text("Welcome", style: TextStyle(fontSize: 20),),
              Text("")
            ],
          ),
        ),
      ),
    );
  


void handleLink(PendingDynamicLinkData? data)
  if(data != null)
    Uri? uri = data.link;
    print(data);
    print(uri);
    if(uri != null)
      Map<String, String>? utmParameters = data.utmParameters?.cast<String, String>();
      print("UTM Source :$utmParameters?["utm_source"]");
      print("UTM Medium :$utmParameters?["utm_medium"]");
      print("UTM Campaign :$utmParameters?["utm_campaign"]");
    
  

 

 

More :

Also go through the detailed playlist tutorial.

https://www.youtube.com/watch?v=videoseries

 

 

By