简体   繁体   English

Flutter - 使用 flutter_local_notifications 轻松显示 AndroidNotification?

[英]Flutter - Display AndroidNotification easily with flutter_local_notifications?

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. message.notification.android也提供了一个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 ?我的问题是,与其创建AndroidNotificationDetailsNotificationDetails等各种对象来显示通知,不如简单地传递RemoteNotificationAndroidNotification并使用flutter_local_notifications显示它?

Yes, when sending the message with only the data payload, that would be a silent notification.是的,当发送仅包含data负载的消息时,这将是一个静默通知。 You can use the information there to create the notification and past it on to the flutter_local_notifications .您可以使用那里的信息来创建通知并将其传递到flutter_local_notifications Eg例如


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

Check this similar question in case you are also doing it for iOS.检查这个类似的问题,以防您也在为 iOS 这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM