我正在使用这个包 awsome_notifications,虽然它在前台和后台都可以工作,但当应用程序被终止时,它只会打开应用程序,它不会推送指定的页面。
在 main() 函数中监听通知流
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));
}
我在这里遗漏了什么??