Search code examples
androidfirebasefluttergoogle-cloud-messaging

How call function with Map<String,dynamic>message in onmessage listen with attribute of remote message in flutter


This is my function in flutter

String getRideRequestId(Map<String,dynamic> message){
  String rideRequestId="";
if(Platform.isAndroid){
  rideRequestId=message['data']['ride_request_id'];
}else{
 rideRequestId=message['ride_request_id'];
}
return rideRequestId;
}

and i wanted to call it in on message listen or onresume


Solution

  • Please check the docs right here: https://firebase.flutter.dev/docs/messaging/usage#foreground-messages

    And I guess you're trying to call the getRideRequestId with the message.data property on the RemoteMessage object.

    Just do it inside the listener function.

    FirebaseMessaging.onMessage.listen((RemoteMessage message) {
      print('Got a message whilst in the foreground!');
      getRideRequestId(message.data);
    });
    

    Please be more specific about the issue you're facing, like do you get any errors while trying this.