firebase - 无法将 Firebase 云消息导入 Flutter 应用程序
问题描述
我创建了一个简单的界面来使用 firebase 云消息服务发送通知。当我使用 firebase - 控制台发送通知时,它会显示通知。但是当我使用我的界面将数据插入到 firebase 时,它没有显示任何内容。我怎么解决这个问题。
Future<void> insertItem() async {
final form = formKey.currentState;
form.save();
Firestore.instance.runTransaction((transaction) async {
await transaction.set(Firestore.instance.collection("Notification").document(), {
'User': _user,
'Title': _title,
'Body': _msg,
});
});}
- 将数据插入 Firebase 代码-
exports.notificationTrigger = functions.firestore
.document("Notification/{notificationId}")
.onCreate((snapshot, context) => {
msgData = snapshot.data();
var userRef = admin.firestore().collection("Token").doc(msgData.User);
return userRef.get().then((doc) => {
if (!doc.exists) {
console.log("No Devices");
} else {
token = doc.data().Token;
var payload = {
notification: {
title: msgData.Title,
body: msgData.Body,
},
data: {
sendername: msgData.Title,
message: msgData.Body,
},
};
return admin
.messaging()
.sendToDevice(token, payload)
.then(() => {
console.log("pushed notification");
})
.catch((err) => {
console.log(err);
});
}
});});
- index.js -
解决方案
推荐阅读
- node.js - 使用 axios 制作 Azure Zip Deploy
- javascript - 无法在 ReactJS 中完美地使用 CSS 中的位置
- javascript - 如何创建定义了 clientX 和 clientY 的鼠标事件
- pdf - 是否有任何 pdf 分析器/调试器来调试 pdf 文件?
- c# - 显示另一个类datagridview中的一个类的数据c#
- architecture - 微服务依赖架构设计模式 - 我如何实际组织我的依赖关系?
- visual-studio - VS 2019 Enterprise:找不到“分析所有测试的代码覆盖率”选项
- r - 在 R 中的 full_join 函数之后从数据框中删除额外的列
- python - 如何使用函数返回的数据
- c++ - 一个 c++ 程序,用于从用户那里获取数组的大小和组件并返回反向数组