firebase - 前台推送通知
问题描述
每当我使用来自 firebase 的云消息发送通知时,推送通知都会强制应用程序进入另一个屏幕,甚至无需用户点击通知。
我希望用户首先点击通知,然后将其推送到另一个屏幕。下面的代码适用于在前台运行的应用程序,我遇到了这个问题。
提前泰。适用于安卓*
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
final routeFromMessage = message.data['route'];
Navigator.of(context).pushNamed(routeFromMessage);
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;
if (notification != null && android != null && !kIsWeb) {
flutterLocalNotificationsPlugin!.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
channel!.id,
channel!.name,
channel!.description,
// one that already exists in example app.
icon: 'launch_background',
),
),
payload: message.data['route'],
);
}
});
解决方案
推荐阅读
- java - maven无法运行测试
- python - Pyramid 不包含在 Python virtualenv 中
- c# - 如何构造输出文件?
- c++ - 你如何使用 Dbo::QueryModel?
- javascript - Javascript:正则表达式搜索并提取“{}”内的字符串
- sql - GBQ SQL:如何找到 X 值的第一个实例并拉出相应的行
- go - 定义函数接收器还是在参数中传递结构指针?
- javascript - 如果我按下一个键但没有使用 JavaScript 释放,如何计算输入框中添加的元素数量
- neo4j - 用于 OSM PointOfInterest 的 Neo4j 中的路由
- python - 当我按下以下代码中的按钮时出现错误:窗口路径名称错误“.!frame”?