0

How are you guys , my problem that my flutter app is connected to mysql db , when the user is registered a string with the class name is saved to shared preferences and there is a wall to post some posts on it , is there any way to work with fcm bassed on the shared preferences string ? Like if the user has this string and posted let all users with the same string get notifications i hope i could make it more uderstandable but i dont know how ! Thanks

Doug Stevenson
  • 236,239
  • 27
  • 275
  • 302

2 Answers2

0

you will get the token id from the device which you can store to the user table so it will use while giving the notification to every device.

For getting the token :

_firebaseMessaging.getToken().then((String token) {
      assert(token != null);
      setState(() {
        _homeScreenText = "Push Messaging token: $token";
      });
      print(_homeScreenText);
    });

this token variable which you can store to the user table and use it while giving the notification to every device.

Christopher Moore
  • 8,731
  • 9
  • 17
  • 33
Abhishek Ghaskata
  • 1,253
  • 1
  • 3
  • 10
  • refer https://stackoverflow.com/questions/54380063/flutter-how-can-i-send-push-notification-programmatically-with-fcm for sending the notification programmatically. – Abhishek Ghaskata Sep 21 '20 at 17:22
  • Ok but i have five classes and evey class hase it own wall if some one posted i want the push notification only for a particular class i hope you got the idea – Nada Khaled Sep 21 '20 at 17:39
0

This sounds like a perfect use-case for using topics to target those messages. Step-wise:

  1. Each device subscribes to the topic based on their class. If they can have multiple classes, they'd subscribe to all topics for those classes.
  2. You then send the message to the correct topic for its class, and FCM will deliver it to all devices subscribed to that topic.

As usual, you will need to perform the actual send operation from a trusted environment, such as your development machine, a server you control, or Cloud Functions.

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645