Create dynamic fire base deep-link and handle link.

edited October 2023 in Flutter

Hello..,

Firstly, we have to create an app in google fire base using our application package name.

After creating the app, go to the option Dynamic link in the app.

In the dashboard we will have create new dynamic link option, So use it to create an new link with our static URL.

Now we have 2 main points to discuss,

1: Create dynamic link from flutter application.

final dynamicLinkParams = DynamicLinkParameters(
  link: Uri.parse("https://webgrid.in/projects/project"),
  uriPrefix: "https://project.page.link",
  androidParameters: const AndroidParameters(packageName: "in.webgrid.project"),
  // iosParameters: const IOSParameters(bundleId: "com.customer.app.ios"),
);
final dynamicLink =await FirebaseDynamicLinks.instance.buildLink(dynamicLinkParams);
return dynamicLink;

Above function will return the dynamic link to share, Then

2: Handling the dynamic link when got clicked.

await WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

// Check if you received the link via `getInitialLink` first
final PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getInitialLink();

if (initialLink != null) {
  final Uri deepLink = initialLink.link;
  final queryParams = deepLink.queryParameters;
  if(queryParams.length > 0) {
    //validating and any queries
  }
}


FirebaseDynamicLinks.instance.onLink.listen(
      (pendingDynamicLinkData) async {
    // Set up the `onLink` event listener next as it may be received here
    if (pendingDynamicLinkData != null) {
      final Uri deepLink = pendingDynamicLinkData.link;
      // Example of using the dynamic link to push the user to a different screen
      final queryParams = deepLink.queryParameters;
      if(queryParams.length > 0) { 
        // verify the username is parsed correctly
       // validating and creating the query
      }
    }
  },
);

Place the above code in main file. By this code we can handle the URL queries.

Note: Creating dynamic link will only works for app not for website, As google disabling the dynamic links on or before 2025. So, Using it on that time will not work.

Thank you...

Tagged:
Sign In or Register to comment.