Search code examples
flutterfirebasepush-notificationflutter-local-notification

How to do firebase push notification with redirect with payload data in flutter.?


Here is my code below :-

var typeId = message!=null?message.data["payload"]:payload;

if(typeId["type"]=="XYZ"){
//Navigate to a screen

}else{}

this is not working and throwing exception.


Solution

  • Your exception is because of you've not decoded your message.data["payload"]. Because Data payload contains custom key-value pairs not a JSON format. you have to decode it.

    here is your solution:

    var typeId = message!=null ?  json.decode(message.data["payload"]) : payload;
    
    if(typeId["type"]=="XYZ"){
    
    //Navigate to a screen
    
    }
    else{
    
    }
    

    happy coding...