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

Actions cause the crash of the entire app #1721

Closed
EnricoTirri opened this issue Sep 25, 2022 · 6 comments · Fixed by #1739
Closed

Actions cause the crash of the entire app #1721

EnricoTirri opened this issue Sep 25, 2022 · 6 comments · Fixed by #1739

Comments

@EnricoTirri
Copy link

Describe the bug
When I show a notification with actions and I try to press one of them the application crash, the warning are referencing to the unability of the system to reach a receiver

To Reproduce
Just show a notification with action and try to press one of the action button, it does not depend whether the application is running or not, it also does not depend on the callback function referenced on onDidReceiveNotificationResponse args.

bug.txt

@MaikuB
Copy link
Owner

MaikuB commented Sep 26, 2022

Can you provide a link to a repository hosting a minimal app that can reproduce the problem?

@fewling
Copy link

fewling commented Oct 4, 2022

I just ran into the same problem, the android JAVA part seems to have a null callback function to handle the action.

Base on the documentation: when initializing the plugin, we can prepare two callbacks:

  • onDidReceiveNotificationResponse
  • onDidReceiveBackgroundNotificationResponse

After setting both callbacks, pressing the actions does not crash anymore.

Caution❗: As the documentation mentioned, onDidReceiveBackgroundNotificationResponse needs to be either static or annotated with the @pragma('vm:entry-point'), but I have to add both to make it stop crashing 🤷‍♂️.

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

main() async {

  /// Initialization part:
  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
      FlutterLocalNotificationsPlugin();

  const AndroidInitializationSettings initializationSettingsAndroid =
      AndroidInitializationSettings('@mipmap/ic_launcher');

  const InitializationSettings initializationSettings =
      InitializationSettings(android: initializationSettingsAndroid);



  /// ⚠⚠⚠ Preparing TWO callbacks here:
  await flutterLocalNotificationsPlugin.initialize(
    initializationSettings,
    onDidReceiveNotificationResponse: onReceiveResponse,                        //  callback A 🅰
    onDidReceiveBackgroundNotificationResponse: onReceiveBackgroundResponse,    //  callback B 🅱
  );
}

  ///  🅰 callback A:
  void onReceiveResponse(
      NotificationResponse notificationResponse) async {
    final payload = notificationResponse.payload;
    log('notification payload: $payload');
  }

  /// 🅱 callback B:
  /// Functions passed to the [onDidReceiveBackgroundNotificationResponse] callback need to be
  /// annotated with the @pragma('vm:entry-point') annotation to ensure they are not stripped out by the Dart compiler.
  @pragma('vm:entry-point')
  static void onReceiveBackgroundResponse(
      NotificationResponse notificationResponse) async {
    final payload = notificationResponse.payload;
    log('Background Notification payload: $payload');
  }

@MaikuB
Copy link
Owner

MaikuB commented Oct 4, 2022

Thanks @fewling, will see if I can reproduce this one though not sure if it's the same problem @EnricoTirri is having

@MaikuB
Copy link
Owner

MaikuB commented Oct 6, 2022

@fewling are you able to provide more code on how you defined your notification and notification actions? Even better, if you're able to provide a link to a repository hosting a minimal app that can reproduce the problem

@fewling
Copy link

fewling commented Oct 6, 2022

"Fixed" the error fews day ago without keeping a record.

Tried reproducing the "wrong" steps I have done in both working project and a new project, but it doesn't show up anymore (🤷‍♂️ not sure why).

Sorry I can't be of more help.

@MaikuB
Copy link
Owner

MaikuB commented Oct 7, 2022

I was able to reproduce in the example app by not listening to the onDidReceiveBackgroundNotificationResponse stream. The crash is actually indicative of trying to setup a notification action that but hasn't been handled. Will fix the crash given that trying to handle the action is optional

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