I am working on a Flutter Project and I'm looking for flutter push notifications. How can I do it so that when a user submits a form, it sends a notification and after that get a notification when we send them an email?


Solution 1: Andrei Marin

Yes, first you need to store the device token used for each account. You can store this in firebase. This is the code used to see a device token:

@override
  void initState()  {
    FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance; // Change here
    _firebaseMessaging.getToken().then((token){
      print("token is $token");
  });
}

just add that device token to firebases specific user

This code is used to send a specific notification

const admin = require("firebase-admin");

await admin.messaging().sendMulticast({
  tokens: ["token_1", "token_2"],
  notification: {
    title: "Weather Warning!",
    body: "A new weather warning has been issued for your location.",
    imageUrl: "https://my-cdn.com/extreme-weather.png",
  },
});

in the tokens you need to put the users token to whom you want to send the notification.

For more info you can check out this page: https://firebase.flutter.dev/docs/messaging/notifications/

I would also recommend watching some youtube videos on it with some exampls