send method

  1. @override
Future send({
  1. required String msg,
  2. required String fcmToken,
  3. required Map<String, dynamic> data,
})
override

Implementation

@override
Future send(
    {required String msg,
    required String fcmToken,
    required Map<String, dynamic> data}) async {
  String accessToken = await getAccessToken();
  String endpointFirebaseCloudMessaging =
      "https://fcm.googleapis.com/v1/projects/navigatorrf-f87c3/messages:send";

  final Map<String, dynamic> message = {
    "message": {
      "token": fcmToken,
      "notification": {
        "title": "FCM Message",
        "body": msg,
      },
      "data": data,
      "android": {
        "notification": {
          "click_action": "FLUTTER_NOTIFICATION_CLICK",
          "sound": "musicrockme.mp3",
        },
      }
    }
  };

  final response = await http.post(Uri.parse(endpointFirebaseCloudMessaging),
      headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer $accessToken"
      },
      body: json.encode(message));

  debugPrint(response.body);
  debugPrint(response.statusCode.toString());
}