I've updated firebase messaging to the latest version and implement the new modifications but with firebase_messaging: ^8.0.0 and above I am not able to navigate to the respective screens when I push the notification icon if the application running in the background.
this is the code
class PushNotificationService
{
final FirebaseMessaging messaging = FirebaseMessaging.instance;
Future initialize(context) async{
FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage message) => (Map<String, dynamic> message) async{
retrieveRideRequestInfo(getRideRequestId(message), context);
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) => (Map<String, dynamic> message) async {
retrieveRideRequestInfo(getRideRequestId(message), context);
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) => (Map<String, dynamic> message) async{
retrieveRideRequestInfo(getRideRequestId(message), context);
});
}
Future<String> getToken() async{
String token = await messaging.getToken();
//String token = await firebaseMessaging.getToken();
print("This is token :: ");
print(token);
driversRef.child(currentfirebaseUser.uid).child("token").set(token);
messaging .subscribeToTopic("alldrivers");
messaging .subscribeToTopic("allusers");
}
String getRideRequestId(Map<String, dynamic> message){
String rideRequestId = "";
if(Platform.isAndroid)
{
rideRequestId = message['data']['ride_request_id'];
}
else{
rideRequestId = message['ride_request_id'];
}
return rideRequestId;
}
void retrieveRideRequestInfo(String rideRequestId, BuildContext context){
newRequestsRef.child(rideRequestId).once().then((DataSnapshot dataSnapshot)
{
if (dataSnapshot.value != null) {
double pickUpLocationLat = double.parse(
dataSnapshot.value['pickup']['latitude'].toString());
double pickUpLocationLng = double.parse(
dataSnapshot.value['pickup']['longitude'].toString());
String pickUpAddress = dataSnapshot.value['pickup_address'].toString();
}
});
}
}
Run log:
D/FLTFireMsgReceiver( 8777): broadcast received for message
W/FLTFireMsgService( 8777): A background message could not be handled in Dart as no onBackgroundMessage handler has been registered.
W/FirebaseMessaging( 8777): Unable to log event: analytics library is missing W/FirebaseMessaging( 8777): Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used. E/NotificationManager( 8777): notifyAsUser: tag=FCM-Notification:111236427, id=0, user=UserHandle{0}