I have Firebase Cloud Messaging set up for my app in Flutter. I have set up everything on the console. I also tested with postman which also works well. However, I also want to test within Flutter by which I know is possible too.
But it doesn't work for me as I do not any notification nor error message. How can this be done?
Future<Map<String, dynamic>> sendAndRetrieveMessage() async {
print("Wdwd");
await firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true, provisional: false),
);
await http.post(
'https://fcm.googleapis.com/fcm/send',
headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'key = $serverToken',
},
body: jsonEncode(
<String, dynamic>{
'notification': <String, dynamic>{
'body': 'this is a body',
'title': 'this is a title'
},
'priority': 'high',
'data': <String, dynamic>{
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'id': '1',
'status': 'done'
},
'to': "tokenString",
},
),
);
final Completer<Map<String, dynamic>> completer =
Completer<Map<String, dynamic>>();
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
completer.complete(message);
},
);
return completer.future;
}
I initiate this code with a button click. Didn't get any response. Please help me out.