11import 'package:flutter_local_notifications/flutter_local_notifications.dart' ;
2+ import 'package:flutter_phoenix/flutter_phoenix.dart' ;
3+ import 'package:fuck_your_todos/main.dart' ;
24
35class NotificationService {
46 static final NotificationService _instance = NotificationService ._internal ();
@@ -37,7 +39,13 @@ class NotificationService {
3739 await flutterLocalNotificationsPlugin.initialize (
3840 settings: initializationSettings,
3941 onDidReceiveNotificationResponse: (NotificationResponse response) async {
40- // Handle notification interaction
42+ if (response.payload == 'restart_app' ||
43+ response.actionId == 'restart_app_action' ) {
44+ final context = navigatorKey.currentContext;
45+ if (context != null ) {
46+ Phoenix .rebirth (context);
47+ }
48+ }
4149 },
4250 );
4351
@@ -65,23 +73,34 @@ class NotificationService {
6573 required String title,
6674 required String body,
6775 String ? payload,
76+ bool showRestartButton = false ,
6877 }) async {
6978 if (! _isInitialized) {
7079 await init ();
7180 }
7281
73- const AndroidNotificationDetails androidPlatformChannelSpecifics =
82+ final AndroidNotificationDetails androidPlatformChannelSpecifics =
7483 AndroidNotificationDetails (
7584 'instant_backup_and_restore_channel_id' ,
7685 'Backup and restore' ,
7786 importance: Importance .max,
7887 priority: Priority .high,
88+ actions: showRestartButton
89+ ? < AndroidNotificationAction > [
90+ const AndroidNotificationAction (
91+ 'restart_app_action' ,
92+ 'Restart App' ,
93+ cancelNotification: true ,
94+ showsUserInterface: true ,
95+ ),
96+ ]
97+ : null ,
7998 );
8099
81100 const DarwinNotificationDetails iosNotificationDetails =
82101 DarwinNotificationDetails ();
83102
84- const NotificationDetails platformChannelSpecifics = NotificationDetails (
103+ final NotificationDetails platformChannelSpecifics = NotificationDetails (
85104 android: androidPlatformChannelSpecifics,
86105 iOS: iosNotificationDetails,
87106 );
@@ -91,7 +110,7 @@ class NotificationService {
91110 title: title,
92111 body: body,
93112 notificationDetails: platformChannelSpecifics,
94- payload: payload ,
113+ payload: 'restart_app' ,
95114 );
96115 }
97116
0 commit comments