如何在通知点击颤动时推送特定页面

时间:2021-07-25 08:05:41

标签: flutter dart

我正在使用这个包 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));
}

我在这里遗漏了什么??

0 个答案:

没有答案
相关问题