0

I do not find an example of how to send topic messages using Firebase Messaging on Flutter. On this tutorial here, it shows how to handle topics but not how to send the message.

So far, I am able to subscribe to a topic using FirebaseMessaging.instance.subscribeToTopic("topic");

I can see that there is a function FirebaseMessaging.instance.sendMessage but don't understand how to use it. I have searched online but cannot find a proper example of how to send messages to users subscribed to a particular topic.

Noor
  • 19,638
  • 38
  • 136
  • 254
  • See https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-topics. And if you're wondering how to do this from your Flutter code, that isn't possible to do securely. Sending messages must always happen from a trusted environment. For more on that, see: https://stackoverflow.com/a/37993724 and https://firebase.google.com/docs/cloud-messaging/fcm-architecture. – Frank van Puffelen Oct 22 '22 at 20:48
  • How about sending just a notification, but this is what I need basically. Is it possible to do so directly using Firebase Flutter SDK? – Noor Oct 23 '22 at 00:13

1 Answers1

2

Your secured backend should handle the sending. On the same page that you linked to, there is a link at the bottom with a good description on how to send to topics.

Link to that documentation:

https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-topics

Robert Sandberg
  • 6,832
  • 2
  • 12
  • 30