我正在使用firebase_messaging进行开发 当有通知到来时,我将显示警示对话框。以下是我的代码。
showNotification(BuildContext context) {
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on message $message');
_showPushNotificationDialog(message['notification']['title'],
message['notification']['body'], context);
},
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
_showPushNotificationDialog(
message['data']['title'], message['data']['body'], context);
},
onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
_showPushNotificationDialog(
message['data']['title'], message['data']['body'], context);
},
);
}
_showPushNotificationDialog
方法将在每次调用onMessage
、onResume
和onLaunch
方法时被调用。
遇到的问题是,当我的应用处于后台或终止模式时,通知会来,并且会点击通知栏时,一切都正常。但当我去其他页面并返回到之前的页面时,每次都会调用_firebaseMessaging.configure(....
方法,它有数据,所以每次都会弹出我的警报对话框。
那么,我该如何清除通过通知栏点击的通知?