4

I'm using firebase_messaging to get push notifications on the app .. I'm sending with the notification a route to display a specific page when clicking on the notification with the help of flutter_local_notification like this: (I've not a good context)

_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) {
  print('on message $message');
  print(message['route']);
  globals.firebaseIn(message['route']);
},
onResume: (Map<String, dynamic> message) {
  print('on resume $message');
  globals.firebaseOut(message['route']);
},
onLaunch: (Map<String, dynamic> message) {
  print('on launch $message');
  globals.firebaseOut(message['route']);
},
);

void firebaseIn(String route) {
showNotificationWithDefaultSound(route);
}

Future onSelectNotification(String payload) async {
 router.navigateTo(currentContext, payload,
  transition: TransitionType.inFromRight,
  transitionDuration: const Duration(milliseconds: 500));
}

Future showNotificationWithDefaultSound(String route) async {
var androidPlatformChannelSpecifics = new 
 AndroidNotificationDetails(
  'your channel id', 'your channel name', 'your channel description',
  importance: Importance.Max, priority: Priority.High);
  var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
  var platformChannelSpecifics = new NotificationDetails(
  androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
 await flutterLocalNotificationsPlugin.show(
0,
'استطلاع جديد',
'لديك استطلاع جديد',
platformChannelSpecifics,
payload: route,
 );
}

 void firebaseOut(String route) {
 router.navigateTo(currentContext, route,
  transition: TransitionType.inFromRight,
  transitionDuration: const Duration(milliseconds: 500));
 }

This works perfectly when the notification is received while the application is open .. but when the application is running on the background or closed and the notification is received, when clicking on the notification the application will open on its state from the background or from the start if it was closed...

I want the specific route to open when clicking on the notification even if it was in the background or closed .. how to do that? is there is a way to achieve this in flutter?

Jérémy Gachon
  • 252
  • 2
  • 6
  • 27

0 Answers0