当使用Firebase Messaging打开应用程序时,Flutter显示通知

时间:2020-04-23 09:46:36

标签: firebase flutter firebase-cloud-messaging

该应用程序会收到我在后台或关闭模式下发送的所有通知,但是我也想在用户玩该应用程序时打开该应用程序时显示该通知。

      onMessage: (Map<String, dynamic> message) async {
        print("onMessage: $message");
        FlutterRingtonePlayer.playNotification();
      },
      onLaunch: (Map<String, dynamic> message) async {
        print("onLaunch: $message");

      },
      onResume: (Map<String, dynamic> message) async {
        print("onResume: $message");
        // TODO optional
      },

1 个答案:

答案 0 :(得分:0)

如果要在系统托盘中显示通知,就像在后台运行应用程序一样,可以使用软件包flutter_local_notifications

这样,当您通过onMessage收到通知时,可以使用以下方式:

AndroidNotificationDetails notificationAndroidSpecifics =
    AndroidNotificationDetails(
        groupChannelId, groupChannelName, groupChannelDescription,
        importance: Importance.Max,
        priority: Priority.High,
        groupKey: groupKey);

NotificationDetails notificationPlatformSpecifics =
    NotificationDetails(notificationAndroidSpecifics, null);

await flutterLocalNotificationsPlugin.show(
    1,
    'Jeff Chang',
    'Please join us to celebrate the...',
    notificationPlatformSpecifics);

查看他们的文档以获取更多示例!