How can i send notification with firebase in app

Viewed 46

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?

1 Answers

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.

Related