问题
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