how to open particular screen on clicking on push notification for flutter

前端 未结 6 1895
我寻月下人不归
我寻月下人不归 2020-12-02 07:14

I am trying to achieve open specific screen on clicking push notification and my payload looks like this:

 var payload = {
        notification: {
                  


        
6条回答
  •  暖寄归人
    2020-12-02 07:33

    A few things here:

    1- click_action has to be set to "FLUTTER_NOTIFICATION_CLICK"

    2- click_action has to be set in the data section of a payload

    DATA='{
      "notification": {
        "body": "this is a body",
        "title": "this is a title"
        "click_action": "FLUTTER_NOTIFICATION_CLICK",
      },
      "data": {
        "sound": "default", 
        "status": "done",
        "screen": "screenA",
      },
      "to": ""
    }'
    

    This should allow you to receive the message in the onMessage handler in your flutter app.

    From there you can call Navigator.of(context).pushNamed(message['screen']).

    If you don't have a BuildContext at that point, you can register a GlobalKey as the navigatorKey property of your MaterialApp, and use it to access your Navigator globally, via GlobalKey.currentState

提交回复
热议问题