单击通知时打开特定的路线

时间:2019-01-23 06:22:00

标签: firebase push-notification dart flutter firebase-cloud-messaging

我正在使用firebase_messaging在应用程序上获取推送通知。.我在flutter_local_notification的帮助下单击通知时,随通知一起发送了显示特定页面的路线这个:

_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));
 }

当打开应用程序时收到通知时,此方法非常有效..但是,当应用程序在后台运行或关闭并接收到通知时,单击通知时,应用程序将从后台状态打开或从一开始就关闭它...

我希望在单击通知时打开特定路线,即使该通知处于后台或关闭状态..该怎么做?有没有办法实现这一目标?

0 个答案:

没有答案