FCM Not working in flutter with firebase_messaging: ^11.4.2
I have try with both old and new data payload for implementing FCM with Topic but when we send the notification from firebase manually . It comes and hit the natively broadcast receiver and message shows but when we send by code and response we get 200 which is fine but the problem in plugin is that is not hit that time broadcast receiver so that message not show.
//<--Here -- sendPushMessageRun Here-->
Future<void> sendPushMessage() async {
if (_token == null) {
print('Unable to send FCM message, no token exists.');
return;
}
try {
final response = await http.post(
Uri.parse('https://api.rnfirebase.io/messaging/send'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'key=A....Q'
},
body: constructFCMPayload(_token),
);
if(response.statusCode == 200){
print('Done!');
await Firebase.initializeApp();
///
await FirebaseMessaging.onMessage.listen((RemoteMessage message) {
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;
if (notification != null && android != null && !kIsWeb) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
channelDescription:channel.description,
// TODO add a proper drawable resource to android, for now using
// one that already exists in example app.
icon: 'launch_background',
),
),
);
}
});
}else{
print('Not Done!'+response.statusCode.toString());
}
} catch (e) {
print(e);
}
}
String constructFCMPayload(String? token) {
_messageCount++;
return jsonEncode({
'topic': "fcm_test", //also try with "to" : "/topics/fcm_test"
'data': {
'via': 'FlutterFire Cloud Messaging!!!',
'count': _messageCount.toString(),
},
'notification': {
'title': 'Hello FlutterFire!',
'body': 'This notification (#$_messageCount) was created via FCM!',
},
});`enter code here`
}