How to start specific screen when notification appear in flutter

≡放荡痞女 提交于 2020-05-28 04:36:07

问题


I am using firebase_messaging for notification, everyting is work fine. I have a video calling screen I want to start this screen on notification when app in background. It's working fine when application in foreground.

here is my firebase integration code:

final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
_firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        Map data = message["data"];
        if (data.isNotEmpty){
          Fcm.startRinging(data);
        } else {
          showNotification(title: "Message", body: "Telemedicine");
        }
      },
      onLaunch: (Map<String, dynamic> message) async {
        Map data = message["data"];
        print("OnLaunch::: $message");
        showNotification(title: "Message", body: "Telemedicine Call");
      },
      onBackgroundMessage: Fcm.myBackgroundMessageHandler,
      onResume: (Map<String, dynamic> message) async {
        Map data = message["data"];
        print("onResume::: $message");

      },
    );

Here I handle payload notification when application in background:

class Fcm{
  static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
    print("hello"+message.toString());

    if (message.containsKey('data')) {
      // Handle data message
      final dynamic data = message['data'];
      await startRinging(data);
      print(data);
    }

    if (message.containsKey('notification')) {
      // Handle notification message
      final dynamic notification = message['notification'];
      print(notification);
    }

    return Future<void>.value();
    // Or do other work.
  }


  static void startRinging(Map<dynamic, dynamic> data) async {
    print("start");
    String docName = data["DoctorName"];
    String docImage = data["DoctorImage"];
    String room = data["RoomName"];
    String token = data["PatientToken"];
    Route route = MaterialPageRoute(builder: (_)=> CallResponse(
        docName: docName,
        docImage: docImage,
        token: token,
        roomName: room
    ));
    <Here I am trying to start next route but i don't have BuildContext>
//    await Navigator.push(context, route);
  }
}

来源:https://stackoverflow.com/questions/61700435/how-to-start-specific-screen-when-notification-appear-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!