Max
Max

Reputation: 93

How to show a push-notification when the application is open(foreground), when OnMessage is triggered?

Im use Flutter and Firebase Messaging. I im configure Firebase like in example:
firebaseMessaging.configure( onMessage: ... onLaunch: ... onResume: ... )
But i wanna see push-notification even when app is open.
Roughly speaking onMessage should work like onResume.
How can i do this?

Upvotes: 0

Views: 99

Answers (1)

Henok
Henok

Reputation: 3383

  onMessage: (Map<String, dynamic> message) async {
        showNotification(message);
        print('on message $message');
      }




  showNotification(Map<String, dynamic> msg) async {
    var android = new AndroidNotificationDetails(
      'your channel id',//channel id
      "your channel name",//channel name
      "your channel description",//channel desc todo set all this right
      icon: 'mipmap/launcher_icon'//add your icon here
    );
    var iOS = new IOSNotificationDetails();
    var platform = new NotificationDetails(android, iOS);


    await flutterLocalNotificationsPlugin
        .show(0, msg['notification']['title'], msg['notification']['body'], platform);


  }

I used flutter_local_notifications: ^1.2.2 to show local notification foreground.

Additionally, if you are implementing for IOS don't forget to ask for notification permission.

Upvotes: 1

Related Questions