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

前端 未结 6 1917
我寻月下人不归
我寻月下人不归 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:22

    Initially, @xqwzts answer not working for me. After a lot of research, I find that We need to initialize the configure method little delay. I attached the code below. It will helpful for others.

    void initState() {
            // TODO: implement initState
            super.initState();
            _firebaseMsgListener();
          }
    
          void _firebaseMsgListener() {
            // if (Platform.isIOS) iOS_Permission();
    
            _firebaseMessaging.getToken().then((token) {
              Fimber.d("=====> token : $token");
              UpdateTokenRequest request = UpdateTokenRequest();
              request.token = token;
              homeBloc.updateFCMToken(request);
            });
    
            Future.delayed(Duration(seconds: 1), () {
              _firebaseMessaging.configure(
                onBackgroundMessage: myBackgroundMessageHandler,
                onMessage: (Map message) async {
                  Fimber.d("=====>on message $message");
                  Fluttertoast.showToast(msg: "onMessage $message");
                },
                onResume: (Map message) async {
                  Fimber.d("=====>onResume $message");
                  Fluttertoast.showToast(msg: "onResume $message");
                },
                onLaunch: (Map message) async {
                  Fimber.d("=====>onLaunch $message");
                  Fluttertoast.showToast(msg: "onLaunch $message");
                },
              );
            });
          }
    
          Future myBackgroundMessageHandler(
              Map message) async {
            print("_backgroundMessageHandler");
            if (message.containsKey('data')) {
              // Handle data message
              final dynamic data = message['data'];
              print("_backgroundMessageHandler data: ${data}");
            }
    
            if (message.containsKey('notification')) {
              // Handle notification message
              final dynamic notification = message['notification'];
              print("_backgroundMessageHandler notification: ${notification}");
              Fimber.d("=====>myBackgroundMessageHandler $message");
            }
            return Future.value();
          }
    

提交回复
热议问题