Home:ALL Converter>Flutter Firebase push notification - no notification

Flutter Firebase push notification - no notification

Ask Time:2021-01-04T14:26:43         Author:Mahi

Json Formatter

I am a beginner in Flutter. When I tried to make push-notification in my app using cloud functions. I don't why I don't get any push-notifications. It's fine When I use the Firebase tool. But not with Cloud functions.

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

exports.myFunction = functions.firestore.document('shop/{doc}/slides/{docs}').onCreate((snapshot, context) => {
  return admin.messaging().sendToTopic('shop', {
    notification: {
        title: snapshot.data().username,
        body: snapshot.data().text,
        clickAction: 'FLUTTER_NOTIFICATION_CLICK',
    },
});
});


main.dart


@override
  void initState() {
    super.initState();
    final fbm = FirebaseMessaging();
    //app in foreground
    fbm.configure(onMessage: (msg) {
      print(msg);
      return;
    },
        //app is terminated.
        onLaunch: (msg) {
      print(msg);
      return;
    },
        //app  in background.
        onResume: (msg) {
      print(msg);
      return;
    });
    fbm.subscribeToTopic('shop');
  }


How to send notifications to all without using token or subscribeTopic()?

Author:Mahi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/65558503/flutter-firebase-push-notification-no-notification
yy