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()?