Want to subscribe to a topic in flutter FCM? You can use subscribeToTopic to send a notification to all devices on login success or somewhere where you want to subscribe.
Here is a quick example:
1 2 3 4 5 6 7 8 9 | FirebaseMessaging firebaseMessaging = new FirebaseMessaging(); void fcmSubscribe() { firebaseMessaging.subscribeToTopic('TopicToListen'); } void fcmUnSubscribe() { firebaseMessaging.unsubscribeFromTopic('TopicToListen'); } |
Test the topic subscription by using firebase console to send the notification to a topic that the device is listening by choosing the topic in target.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.