I am trying to achieve open specific screen on clicking push notification and my payload looks like this:
var payload = {
notification: {
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();
}