Alternate for firebase dynamic link in flutter

427 Views Asked by At

Objective: Send deep link using push notification. Flutter app will receive deep link through push notification and navigate to specific screen.

Planned to use firebase dynamic link to achieve above objective. But firebase is going to depreciated from August, 25, 2025.

Can someone help on other way to achieve the above objective in flutter. Alternate to firebase dynamic link in flutter.

Expectation: Send deep link using push notification. Flutter app will receive deep link through push notification and navigate to specific screen.

Tried: Firebase dynamic link

1

There are 1 best solutions below

0
James On

Expectation: Send deep link using push notification. Flutter app will receive deep link through push notification and navigate to specific screen.

Yes, a Flutter app can receive a deep link through a push notification and navigate to a specific screen.

The main steps:

  1. Sending the push notification with the deep link:i'm using Firebase Cloud Messaging (FCM) but any other push notification service is ok.
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;

Future<void> sendNotification() async {
 await _firebaseMessaging.sendMessage(
  to: "<FCM TOKEN>",
  data: {
    "click_action": "FLUTTER_NOTIFICATION_CLICK",
    "screen": "screenA",
  },
  notification: const Notification(
    title: 'Title',
    body: 'Body',
  ),
 );
}

The "screen" key in the data map is the deep link that will be used to navigate to a specific screen in your Flutter app Source.

  1. Handling the deep link when the app is opened from a push notification: We're using the FirebaseMessaging.onMessageOpenedApp:
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
 print('Just received a notification when app is opened');
 if(message.data["screen"] != null){
  Navigator.of(context).pushNamed(message.data["screen"]);
 }
});

This will listens for when a message is opened from a push notification and then navigates to the screen specified in the "screen" key of the message's data Source.

  1. Handle incoming deep links in your Flutter application:

You can also check for incoming link in your app:

Future<void> main() async {
 WidgetsFlutterBinding.ensureInitialized();
 final deferredDeeplink = await _getDeferredDeeplink();
 runApp(MaterialApp(
   initialRoute: deferredDeeplink,
 ));
}

Future<String?> _getDeferredDeeplink() async {
 if (await Clipboard.hasStrings() == false) {
   return null;
 }
 final content = await Clipboard.getData('text/plain');
 if (content == null) {
   return null;
 }
 // now you need to check whether the content matches
 // the format of your associated website.
 if (content.data.startsWith('https://example.org')) {
   // The initial route property of MaterialApp expects the deeplink 
   // to start with a '/'
   return content.data.replaceFirst('https://example.org', '');
 }
 return null;
}