Search code examples
flutterpush-notificationfirebase-cloud-messagingapple-push-notificationsgoogle-cloud-messaging

Is there a way to use cloud messaging without displaying a notification in Flutter using Firebase or other cloud messaging platforms?


i am developing a mobile application using Flutter. I was wondering if we can use Cloud Messaging for data transfer or event listening purposes without giving user an actual app notification if app is currently running.

For example;

  • User taps on "make payment" button and result of that payment process is produced from an async method in a microservice that we don't know when it will return the result thus we can not synchronously wait the result on mobile.

Can i use cloud messaging for these purposes without popping up a notification?

Thank you for your answers and time..


Solution

  • Are saying like listening some notification data something like this

    // This is when app is running not on background   
          FirebaseMessaging.onMessage.listen((RemoteMessage? message) {
            RemoteNotification? notification = message!.notification;
            // just use message!.data it depends on you
            // notification!.data
            // is always return Map e.g. { "id":"sampleId"}
           // so call it like notification!.data["id"]
            if(notification!.data!= null){
                  // Do your thing here.
             }
            
             });