Flutter-点击通知时打开页面
我正在使用很棒的通知开发颤振应用程序。我想在单击通知时重定向到通知页面。
初始化 main.dart 通知:
AwesomeNotifications().initialize(
'resource://drawable/ic_stat_ida',
[
NotificationChannel(
channelKey: 'notification_channel',
channelName: 'Normal Notifications',
channelDescription: 'Notification channel for normal notifications',
defaultColor: Color(0xFFffa473),
ledColor: Colors.white,
importance: NotificationImportance.High,
playSound: true,
enableLights: true,
enableVibration: true,
channelShowBadge: false)
],
debug: true);
如果应用程序关闭,我在启动屏幕上执行以下操作:
void initState() {
super.initState();
AwesomeNotifications().actionStream.listen((receivedAction) {
var payload = receivedAction.payload;
print(payload);
result = true;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrganizerNotificationScreen(
taskId: receivedAction.id.toString(),
taskBody: receivedAction.body,
),
));
});
}
这是成功的。 但我想在应用程序打开时在任何页面上单击通知时进行重定向。
void listenOrganizerNotification(context) {
AwesomeNotifications()
.actionStream
.listen((ReceivedNotification receivedNotification) {
print('event received!');
print(receivedNotification.toMap().toString());
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrganizerNotificationScreen(
taskId: receivedNotification.id.toString(),
taskBody: receivedNotification.body,
),
));
});
}
我应该在哪里编写监听和重定向函数?
I am developing flutter application using awesome notification. I want to redirect to notification page when notification is clicked.
Initialize main.dart notification:
AwesomeNotifications().initialize(
'resource://drawable/ic_stat_ida',
[
NotificationChannel(
channelKey: 'notification_channel',
channelName: 'Normal Notifications',
channelDescription: 'Notification channel for normal notifications',
defaultColor: Color(0xFFffa473),
ledColor: Colors.white,
importance: NotificationImportance.High,
playSound: true,
enableLights: true,
enableVibration: true,
channelShowBadge: false)
],
debug: true);
If the application is closed, I do the following on splashscreen:
void initState() {
super.initState();
AwesomeNotifications().actionStream.listen((receivedAction) {
var payload = receivedAction.payload;
print(payload);
result = true;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrganizerNotificationScreen(
taskId: receivedAction.id.toString(),
taskBody: receivedAction.body,
),
));
});
}
This is succesful.
But I want to redirect when the notification is clicked on any page while the application is open.
void listenOrganizerNotification(context) {
AwesomeNotifications()
.actionStream
.listen((ReceivedNotification receivedNotification) {
print('event received!');
print(receivedNotification.toMap().toString());
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrganizerNotificationScreen(
taskId: receivedNotification.id.toString(),
taskBody: receivedNotification.body,
),
));
});
}
Where should I write listen and redirect function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过用 Navigator 替换 AutoRouter,它应该按有人值守的方式工作。您必须检查当前页面然后与目标页面进行比较。
By replacing AutoRouter by Navigator it should work as attended. You must check the current page then compare with the target page.