setupInteractedMessage method
Future<void>
setupInteractedMessage(
)
Implementation
Future<void> setupInteractedMessage() async {
await Firebase.initializeApp();
// Get any messages which caused the application to open from a terminated state.
// If you want to handle a notification click when the app is terminated, you can use `getInitialMessage`
// to get the initial message, and depending in the remoteMessage, you can decide to handle the click
// This function can be called from anywhere in your app, there is an example in main file.
// RemoteMessage? initialMessage = await FirebaseMessaging.instance.getInitialMessage();
// If the message also contains a data property with a "type" of "chat",
// navigate to a chat screen
// if (initialMessage != null && initialMessage.data['type'] == 'chat') {
// Navigator.pushNamed(context, '/chat',
// arguments: ChatArguments(initialMessage));
// }
// Also handle any interaction when the app is in the background via a
// Stream listener
// This function is called when the app is in the background and user clicks on the notification
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
var id = "";
var contentType = "";
var image = "";
var messageData = "";
print('Data Payload:${message.data.toString()}');
message.data.forEach((key, value) {
if (key == "id") {
id = value;
}
if (key == "content_type") {
contentType = value;
}
if (key == "image") {
image = value;
}
if (key == "message") {
messageData = value;
}
});
print('<><> onMessageOpenedApp id--->$id');
print('<><> onMessageOpenedApp contentType--->$contentType');
NavigationService.notif_id = id;
openPage(contentType);
});
await enableIOSNotifications();
await registerNotificationListeners();
}