Atiq Ur Rehman
Atiq Ur Rehman

Reputation: 1233

Flutter Show Notification when app is open with Firebase Messaging

the app receives all the notification that I have sent in the background or closed mode, but I also want to show the notification when the app is opened while user playing with the app.

      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
      },

Upvotes: 5

Views: 7367

Answers (1)

Francisco Javier Snchez
Francisco Javier Snchez

Reputation: 1003

If you want to show the notification in the System tray, as it does when the app is in the background, you can use the package flutter_local_notifications.

This way, when you receive a notification via onMessage, you can use something like this:

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);

Check their documentation for more examples!

Upvotes: 3

Related Questions