1

In my application, there are users who can send messages and only see incoming messages. Messages go according to the sections of the users. So far, no problem. When the message comes, it should also come in the notification. I have a service for this.

import ‘package:askon_notification/model/message.dart’;
import ‘package:askon_notification/model/user.dart’;
import ‘package:http/http.dart’ as http;

class SendNotificationService{

   Future<bool> sendNotification(Messages sendMessage, MyUser sendingUser, String topic) async{
      var endURL = Uri.parse(‘https://fcm.googleapis.com/fcm/send’);
      String firebaseKey =“AAAA3**********************************”;

      Map<String, String> headers = {
      "Content-Type" : "application/json",
      "Authorization" : "key=$firebaseKey"
      };

      String json = '{ "to" : "topic/$topic", "data" : { "message" : "test", "title" : "baslik" } 
      }';

      http.Response response = await http.post(endURL, headers:  headers, body: json);

      if(response.statusCode == 200){
         print("işlem başarılı");
         return true;
      }else{
         print("işlem başarısız");
         return false;
      }
   }
}

Although I see the operation successful message, the application does not receive any notification. What method should I follow?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ahmetkrakaya
  • 33
  • 1
  • 5
  • *firebaser here* Calls to the FCM REST API require that you specify the FCM *server** key in your code. As its name implies, this key should only be used in server-side code, or in an otherwise trusted environment. The reason for this is that anyone who has the FCM server key can send whatever message they want to all of your users. By including this key in your Android/iOS app, a malicious user can find it and you're putting your users at risk. See https://stackoverflow.com/a/37993724 for a better solution. – Frank van Puffelen Dec 10 '21 at 15:28

1 Answers1

1

The FirebaseApp fetches the notifications from the backend but it needs some configuration to show them. Here's a link to the documentation that will help you to receive the notifications.

bharats
  • 366
  • 2
  • 9