'How to push a specific page on notification tap flutter
I am using this package awsome_notifications, although its working both in foreground and background, when application is killed it only opens the app,it doesn't push the assigned page.
Listening to notification streams up in main() function
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
final AwesomeNotifications awesomeNotifications = AwesomeNotifications();
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
awesomeNotifications.initialize('resource://drawable/splash', [
NotificationChannel(
channelKey: 'basic_channel',
channelName: 'Basic notifications',
channelDescription: 'Notification channel for basic tests',
defaultColor: kPrimaryColor,
ledColor: Colors.white)
]);
await awesomeNotifications.isNotificationAllowed().then((isAllowed) {
if (!isAllowed) {
AwesomeNotifications().requestPermissionToSendNotifications();
}
});
await awesomeNotifications.actionStream.listen((receivedNotification) {
if (receivedNotification.id == 0) {
navigatorKey.currentState!
.pushNamed('/notification', arguments: receivedNotification.payload);
}
if (receivedNotification.id == 1) {
navigatorKey.currentState!.pushNamed('/secondary_notification',
arguments: receivedNotification.payload);
}
});
...
runApp(MyApp(token: token));
}
I am I missing some thing here??
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
