【问题标题】:Error: No named parameter with the name 'onSelectNotification'错误:没有名为“onSelectNotification”的命名参数
【发布时间】:2023-01-03 13:17:26
【问题描述】:
class HelperNotification {

  static Future<void> initialize(FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin) async {
    var androidInitialize = new AndroidInitializationSettings('notification_icon');
    var iOSInitialize = new DarwinInitializationSettings();
    var initializationsSettings = new InitializationSettings(android: androidInitialize, iOS: iOSInitialize);
    flutterLocalNotificationsPlugin.initialize(initializationsSettings, onSelectNotification:(String? payload) async {

      try{
        if(payload != null && payload.isNotEmpty) {

          // Get.toNamed(RouteHelper.getOrderDetailsRoute(int.parse(payload)));
        }else {

          //  Get.toNamed(RouteHelper.getNotificationRoute());
        }
      }catch (e) {}
      return;
    });
    await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
      alert: true,
      badge: true,
      sound: true,

    );

我发现本地通知包有更新,但我试图暗示它但没有成功,你能帮我弄清楚吗?

【问题讨论】:

    标签: flutter flutter-dependencies flutter-test dart-null-safety flutter-local-notification


    【解决方案1】:

    flutter_local_notifications 插件的版本 10.0.0 起,他们删除了 onSelectNotification 参数。您可以在他们的变更日志中阅读更多相关信息:

    重大变化回调现在已被重新设计。现在有 以下回调和两者都将传递一个实例 NotificationResponse 类 onDidReceiveNotificationResponse:已调用 仅在应用程序运行时。这适用于用户选择时 通知或通知操作。这取代了 onSelectNotification之前存在的回调。通知 动作,动作需要配置为指示应用程序或 调用此操作时应显示用户界面 要调用的回调,即通过指定 iOS 上的 DarwinNotificationActionOption.foreground 选项和 Android 上的 showsUserInterface 属性。在 macOS 和 Linux 上,因为有 不支持后台隔离,它将始终调用此回调 onDidReceiveBackgroundNotificationResponse:在后台调用 当用户选择通知操作时隔离。这个 替换 onSelectNotificationAction 回调

    在这里阅读更多:https://pub.dev/packages/flutter_local_notifications/changelog

    【讨论】:

      猜你喜欢
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 2023-01-16
      • 2021-10-06
      • 2021-05-21
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      相关资源
      最近更新 更多