The question is same as here Call onMessage method when the app is in background in flutter and I am following the thread but since there is no response, I am asking this question again.
I've connected my Flutter app with Firebase Messaging and I am receiving notification when my app is in Foreground using the Flutter Local Notifications Plugin. But I cannot receive any notification when my app is in Background
Following is my code:
// FIREBASE CONFIGURATION & HANDLING
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
debugPrint("onMessage: $message");
final notification = message['data']['notification'];
Map responseBody = convert.jsonDecode(notification);
_showNotification(
icon: responseBody['icon'],
title: responseBody['title'],
body: responseBody['body'],
);
setState(() {});
},
);
// DISPLAY NOTIFICATION - HEADS UP
Future<void> _showNotification({String icon, String title, String body}) async {
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'your channel id',
'your channel name',
'your channel description',
importance: Importance.Max,
priority: Priority.High,
ticker: 'ticker',
);
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
0,
title,
body,
platformChannelSpecifics,
);
}
Can someone please guide me how can I receive notifications when my app is in Background