I have integrated firebase-messaging plugin for notification but on clicking notification app is not opening if it is in the background or killed.I want to open app when i click on the natification.
Below is my code for same
void firebaseCloudMessagingListeners() {
FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
_firebaseMessaging.getToken().then((token){
print(token);
});
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
_showNotificationWithDefaultSound(message['notification']['body']);
print('on message $message');
return;
},
onResume: (Map<String, dynamic> message) async {
_showNotificationWithDefaultSound(message['data']['body']);
print('on message $message');
return;
},
onLaunch: (Map<String, dynamic> message) async {
_showNotificationWithDefaultSound(message['data']['body']);
print('on message $message');
},
);
}
_showNotificationWithDefaultSound(message) async {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
new FlutterLocalNotificationsPlugin();
var android = new AndroidInitializationSettings('@mipmap/ic_launcher');
var ios = new IOSInitializationSettings();
var initSettings = new InitializationSettings(android, ios);
flutterLocalNotificationsPlugin.initialize(initSettings,
onSelectNotification: onSelectNotification);
var android1 = new AndroidNotificationDetails(
'channel id', 'channel NAME', 'channel DESCRIPTION',
importance: Importance.Max, priority: Priority.High, ticker: 'ticker');
var ios1 = new IOSNotificationDetails();
var platform = new NotificationDetails(android1, ios1);
await flutterLocalNotificationsPlugin
.show(0, message, 'App Notification!', platform, payload: message);
}