gpt4 book ai didi

How to send a notification from web dashboard to flutter app using firebase cloud messaging(如何使用Firebase云消息将通知从Web仪表盘发送到Ffltter应用程序)

转载 作者:bug小助手 更新时间:2023-10-24 22:02:50 28 4
gpt4 key购买 nike



In my new project i have an admin panel and a driver's app ,When The driver asks for permission to deliver an order It's directed to the dashboard So the admin can allow or not , What I want to do is showing a notification to the driver contains the answer of the admin, I found a way to send notifications through postman but I want to send this notification from the dashboard, or any flutter app in general using dart code.

在我的新项目中,我有一个管理面板和一个司机的应用程序,当司机请求许可交付订单时,它被定向到仪表板,以便管理员可以允许或不允许,我想要做的是向司机显示一个通知,其中包含管理员的答案,我找到了一种通过邮递员发送通知的方法,但我想从仪表板或任何颤动应用程序发送此通知,一般使用DART代码。


Summary(Is there a way to send firebase notifications using dart code.).

摘要(是否有使用DART代码发送Firebase通知的方法。)


I would be grateful for any answer

如有任何答复,我将不胜感激


更多回答

If you are able to send the notification from the postman, then it is easy to make an HTTP request from dart code using HTTP or dio package to send a notification. Here is another solution if you are in a flutter firebase echo system, use firebase functions to build and send the notification from using cloud messaging on the trigger of Firestore events or use http call function of Firebase. If you are using the Firestore, the firebase function will automatically triggered. and if not, use the http-based function which will do anything using node.js.

如果您能够从邮递员发送通知,则很容易使用HTTP或DIO包从DART代码发出HTTP请求来发送通知。这是另一种解决方案,如果您在颤动的Firebase回应系统中,使用FireBase函数构建并发送通知,在FiRestore事件触发时使用云消息传递或使用Firebase的http调用函数。如果您使用的是FiRestore,则Firebase功能将自动触发。如果不是,则使用基于http的函数,该函数将使用node.js执行任何操作。

优秀答案推荐

You can use the http package to send notification

您可以使用http包来发送通知。



import 'package:http/http.dart' as http;
import 'dart:convert';


Future<void> sendNotification(title, body, to) async {

//set fcm token
const fcmToken = 'YOUR_FCM_TOKEN_HERE';

try {
var url = 'https://fcm.googleapis.com/fcm/send';
var header = {
'Content-Type': 'application/json',
'Authorization': 'key=$fcmToken',
};
var request = {
'notification': {
'title': title,
'body': body,
},
'priority': 'high',
'to': '$to',
};

var response = await http.post(
Uri.parse(url),
headers: header,
body: json.encode(request),
);

print(response.body);
} catch (error) {
print(error);
}
}


Then call the function and pass the data

然后调用该函数并传递数据



sendNotification('Notification Title', 'Body', recipient);

Don't forget to change the FCM_TOKEN.

不要忘记更改FCM_TOKEN。


更多回答

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com