How to open Deep Links on Notification Click

Hello FlutterFlow Community,

I hope this message finds you well. We are currently facing an issue in our FlutterFlow project related to opening deep links upon the click of notifications received from Firebase. We have implemented a cloud function for sending notifications, and while the notifications are being received successfully, we are struggling to navigate to the required pages upon clicking them.

Here is a snippet of our cloud function:

const admin = require("firebase-admin");
const functions = require("firebase-functions");

exports.sendNotification = functions.firestore

  .document("notifications/{notificationId}")

  .onCreate(async (snapshot, context) => {

    const notificationData = snapshot.data();

    const notificationType = notificationData.notification_type;

    const receiverRef = notificationData.receiver;

    const senderRef = notificationData.sender;

    const senderSnapshot = await senderRef.get();

    const fcmTokensSnapshot = await receiverRef.collection('fcm_tokens').get();

    const tokens = fcmTokensSnapshot.docs.map(doc => doc.data().fcm_token);

    let title = "";

    switch (notificationType) {

      case "request":

        title = "New Request!";

        break;

      case "Default Screen":

        title = "New Screen!";

        break;

      default:

        title = "Notification";

    }

    let body = "";

    switch (notificationType) {

      case "request":

        body = ${senderSnapshot.data().full_name} wants to connect with you.;

        break;

      case "NewScreen":

        body =  created by ${senderSnapshot.data().full_name}.;

        break;

      default:

        body = "You have a new notification.";

    }

    let deepLinkpath = "";

    switch (notificationType) {
      case "friend_request":
        deepLinkpath = `/addBuddyPage`;
        break;
      case "slamBet":
        deepLinkpath = `/homePage`;
        break;
      default:
        deepLinkpath = "/homePage";
    }

    if (tokens.length > 0) {
      const message = {
        tokens: tokens,
        notification: {
          title: title,
          body: body,
          click_action: "example://example.page.link/${deepLinkpath}",
        },
      };

      admin.messaging().sendMulticast(message)

        .then((response) => {

          console.log("Successfully sent message:", response);

        })

        .catch((error) => {

          console.log("Error sending message:", error);

        });

    }

  });

We are try to use deep links in the click_action property of the notification, as shown in the code above. The deep links are intended to navigate users to specific pages in our FlutterFlow app.

However, despite our efforts, we are unable to deploy cloud function on firebase using the click_action , we are trying to open the expected pages when the user clicks on the notification. We are reaching out to the community to seek assistance or guidance on resolving this issue. If anyone has experience with handling deep links in FlutterFlow and can offer insights into what might be causing the problem, we would greatly appreciate your help.

Thank you in advance for your time and support.

3
2 replies