File tree Expand file tree Collapse file tree 3 files changed +16
-17
lines changed
Expand file tree Collapse file tree 3 files changed +16
-17
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,11 @@ Future<void> main({bool testing = false}) async {
5555
5656 runApp (const FreeCodeCampMobileApp ());
5757
58+ WidgetsBinding .instance.addPostFrameCallback ((_) async {
59+ await NotificationService ().requestPermission ();
60+ await DailyChallengeNotificationService ().setupNotifications ();
61+ });
62+
5863 await QuickActionsService ().init ();
5964}
6065
Original file line number Diff line number Diff line change @@ -49,21 +49,11 @@ class DailyChallengeNotificationService {
4949 initializationSettings,
5050 onDidReceiveNotificationResponse: _onNotificationResponse,
5151 );
52+ }
5253
53- bool permissionGranted = false ;
54- if (Platform .isAndroid) {
55- permissionGranted = await _flutterLocalNotificationsPlugin
56- .resolvePlatformSpecificImplementation<
57- AndroidFlutterLocalNotificationsPlugin > ()
58- ? .requestNotificationsPermission () ??
59- false ;
60- } else {
61- // For iOS, we assume permission is granted after init
62- permissionGranted = true ;
63- }
54+ Future <void > setupNotifications () async {
55+ final permissionGranted = await areSystemNotificationsEnabled ();
6456
65- // Auto-enable daily notifications if system permission is granted
66- // and user hasn't explicitly disabled them
6757 if (permissionGranted) {
6858 final prefs = await SharedPreferences .getInstance ();
6959 final hasSetPreference =
Original file line number Diff line number Diff line change @@ -28,13 +28,17 @@ class NotificationService {
2828 );
2929
3030 await _flutterLocalNotificationsPlugin.initialize (initializationSettings);
31+ }
3132
33+ Future <bool > requestPermission () async {
3234 if (Platform .isAndroid) {
33- await _flutterLocalNotificationsPlugin
34- .resolvePlatformSpecificImplementation<
35- AndroidFlutterLocalNotificationsPlugin > ()
36- ? .requestNotificationsPermission ();
35+ return await _flutterLocalNotificationsPlugin
36+ .resolvePlatformSpecificImplementation<
37+ AndroidFlutterLocalNotificationsPlugin > ()
38+ ? .requestNotificationsPermission () ??
39+ false ;
3740 }
41+ return true ;
3842 }
3943
4044 Future <void > showNotification (String title, String body) async {
You can’t perform that action at this time.
0 commit comments