【问题标题】:Flutter - Display AndroidNotification easily with flutter_local_notifications?Flutter - 使用 flutter_local_notifications 轻松显示 AndroidNotification?
【发布时间】:2023-01-17 03:22:39
【问题描述】:

来自官方文档:

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 还提供了一个 AndroidNotification 对象。

我的问题是,与其创建诸如AndroidNotificationDetails 和NotificationDetails 之类的各种对象来显示通知,不如简单地传递这个RemoteNotification 或AndroidNotification 并使用来显示它flutter_local_notifications?

【问题讨论】:

    标签: flutter firebase firebase-cloud-messaging flutter-dependencies


    【解决方案1】:

    是的,当仅使用 data 负载发送消息时,这将是静默通知。您可以使用那里的信息创建通知并将其传递到flutter_local_notifications。例如。

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

    检查这个类似的question,以防你也在为 iOS 做这件事。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-06
      • 1970-01-01
      • 2013-03-20
      相关资源
      最近更新 更多