Here I have two Applications. One acts like Admin and the other is a customer.
When I'm uploading an image in the admin App that image was displayed in the customer app. Here am using PHP as a backend to post images in the admin app and to get images in the customer app. My question is - I want to send a notification to the customer when the admin uploads the image.
Note: If possible, I need to do this task without using Firebase.
Thanks in Advance.
CodePudding user response:
Before start make sure your project is pointing to the Firebase servers. This can be done by opening pubspec.yaml file and adding the below code. To add a library to your flutter application, you need to follow the steps mentioned below.
CodePudding user response:
I try to explain the process in steps:
Assuming your Flutter app is properly integrated with Firebase FCM
Admin post an image
Server sends a push notification, you may refer to fcm http protocol here or the json structure of your fcm body below
{
"to" : "<TOKEN>", //if you want the fcm to be sent to specific user
"notification" : {
"title": "Notification Title",
"body" : "Notification Body"
},
"data":{
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"key": "<ANY STRING YOU WOULD LIKE TO DIFFERENTIATE THE NOTIFICATION>" //eg: "image_update"
}
}
- In Flutter code, configure
onMessage
to tell the app what is needed to be performed when the push notification with key "image_update" is received
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
if(message.data['key'] == "image_update"){
//call GET image API and display on app
}
//note: you can differentiate notification type with "key" so that you can perform different functions for each notification type
return;
});