提问人:Yellow_Ananas 提问时间:11/15/2023 最后编辑:Munsif AliYellow_Ananas 更新时间:11/15/2023 访问量:47
Flutter FirebaseMessaging。发送通知时出错:类型“Null”不是类型转换中类型“Object”的子类型
Flutter FirebaseMessaging. Error sending notification: type 'Null' is not a subtype of type 'Object' in type cast
问:
Future<void> sendNotificationToUser(String friendUid, String? title, String? body) async {
try {
DocumentSnapshot friendSnapshot = await FirebaseFirestore.instance.collection('users').doc(friendUid).get();
String? friendFcmToken = await friendSnapshot['token_push'];
print("friendFcmToken $friendFcmToken");
await _firebaseMessaging.requestPermission();
final String? fcmToken = await _firebaseMessaging.getToken();
if (friendFcmToken != null) {
await _firebaseMessaging.sendMessage(
to: friendFcmToken,
data: {
'title': title!,
'body': body!,
},
);
print('Notification sent successfully');
} else {
print('Friend user does not have an FCM token');
}
} catch (e) {
print('Error sending notification: $e');
}
}
您好,我是第一次使用 FirebaseMessaging,遇到了一个问题。
请帮我弄清楚问题出在哪里。
我在聊天中发送通知。
答:
0赞
Shahed Emon
11/15/2023
#1
data: {
'title': title ?? '',
'body': body ?? '',
},
评论
0赞
Yellow_Ananas
11/15/2023
不,它没有帮助
0赞
Shahed Emon
11/15/2023
String? friendFcmToken = friendSnapshot['token_push'] as String?;
你能试试这个吗?
0赞
Yellow_Ananas
11/15/2023
问题仍然存在,也许我做错了什么?您能简要描述一下各个阶段吗?
0赞
Shahed Emon
11/15/2023
https://github.com/firebase/flutterfire/issues/10951 对不起
评论
fcmToken