0

From the official documentation:

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
  print('Got a message whilst in the foreground!');
  print('Message data: ${message.data}');

  if (message.notification != null) {
    print('Message also contained a notification: ${message.notification}');
  }
});

message.notification.android also provides an AndroidNotification object.

My question is, rather than creating various objects such as AndroidNotificationDetails and NotificationDetails to show a notification, can I simply pass this RemoteNotification or AndroidNotification and display it using flutter_local_notifications?

Jiehfeng
  • 753
  • 7
  • 16

1 Answers1

0

Yes, when sending the message with only the data payload, that would be a silent notification. You can use the information there to create the notification and past it on to the flutter_local_notifications. E.g.


{
  data: {
    'message': 'Some message'
    'value_1': 'Some value'
  },
  topic: 'some_topic'
}

Check this similar question in case you are also doing it for iOS.

Gerardo
  • 3,460
  • 1
  • 16
  • 18