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
Comments
Can you provide a link to a repository hosting a minimal app that can reproduce the problem? |
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:
After setting both callbacks, pressing the actions does not crash anymore. Caution❗: As the documentation mentioned, 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');
} |
Thanks @fewling, will see if I can reproduce this one though not sure if it's the same problem @EnricoTirri is having |
@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 |
"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. |
I was able to reproduce in the example app by not listening to the |
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
The text was updated successfully, but these errors were encountered: