Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 The named parameter 'onDidReceiveLocalNotification' isn't defined in DarwinInitializationSettings #51

Open
RulyOctareza opened this issue Feb 5, 2025 · 1 comment

Comments

@RulyOctareza
Copy link

I encountered an issue when implementing flutter_local_notifications on iOS. The error occurs when initializing DarwinInitializationSettings with the parameter onDidReceiveLocalNotification.

The named parameter 'onDidReceiveLocalNotification' isn't defined.
Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'onDidReceiveLocalNotification'.

Steps to Reproduce:

  • Add flutter_local_notifications to pubspec.yaml.
  • Initialize DarwinInitializationSettings with onDidReceiveLocalNotification.
  • Run the app on an iOS device.
  • Observe the compilation error.

Expected Behavior:
The onDidReceiveLocalNotification parameter should either be supported or clearly documented as removed in the latest version. If removed, alternative methods should be provided in the documentation.

Actual Behavior:
The parameter onDidReceiveLocalNotification is not recognized, causing a compilation error.

Proposed Solution:
Update the documentation to clarify that onDidReceiveLocalNotification has been removed.
Suggest using onDidReceiveNotificationResponse instead in the flutterLocalNotificationsPlugin.initialize() method.
Environment:
Flutter Version: 3.24.5
Plugin Version: flutter_local_notifications: ^18.0.1
Platform: iOS
iOS Version: 18.0

For now, I replaced:

final initializationSettingsDarwin = DarwinInitializationSettings(
  requestAlertPermission: false,
  requestBadgePermission: false,
  requestSoundPermission: false,
  onDidReceiveLocalNotification: (int id, String? title, String? body, String? payload) async {
    didReceiveLocalNotificationStream.add(
      ReceivedNotification(id: id, title: title, body: body, payload: payload),
    );
  },
);

with:

final initializationSettingsDarwin = DarwinInitializationSettings(
  requestAlertPermission: false,
  requestBadgePermission: false,
  requestSoundPermission: false,
);

and then handled notification with:

await flutterLocalNotificationsPlugin.initialize(
  initializationSettings,
  onDidReceiveNotificationResponse: (notificationResponse) {
    final payload = notificationResponse.payload;
    if (payload != null && payload.isNotEmpty) {
      selectNotificationStream.add(payload);
    }
  },
);
@waffiqaziz
Copy link

waffiqaziz commented Feb 5, 2025

Since flutter_local_notifications-v18.0.0 the onDidReceiveLocalNotification has been removed as it was only relevant for older iOS versions (iOS versions older than 10). You have two options to resolve this:

  1. Downgrade to an older version. As you can see here the project uses version 17.1.2
  2. Continue using the latest version by adapting your code to handle notifications without relying on onDidReceiveLocalNotification like you did above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants