I have an app built on Flutter (firebase) and I am using the cloud Function to send notifications. I want to show/hide notifications based on condition. The condition is, if a user is in the range of 50 km then the notification should show otherwise it should hide. This condition should work if the app is in the foreground/background/ or killed.
To calculate the range I am having lat/long for a user which I am getting from FireStore and the second lat/long I am getting from notification payload.
I have read the official document to handle notifications but my case is different than the example given here https://firebase.flutter.dev/docs/messaging/notifications/
Here is the skeleton of the cloud function
enter code here
var flutterMessage = {
data:
{
"id": docID,
"companyId": companyId,
"userId": userId,
-
-
-
-
some more data
-
-
-
-
"latitude": JSON.stringify(latitude),
"longitude": JSON.stringify(longitude),
},
notification: {
title: title,
body: companyName,
},
apns: {
payload: {
aps: {
sound: "default",
},
},
},
topic: 'New-Doc',
};
let flutterResponse = await admin.messaging().send(flutterMessage).catch((error) => {console.log("Error " + error);});
console.log("response Flutter App" + flutterResponse);
});