From df39a2391bdf01ee446ce02877f6ba89c436f119 Mon Sep 17 00:00:00 2001 From: Pawan Acharya Date: Fri, 25 Oct 2024 18:18:57 +0545 Subject: [PATCH] fix: handle scheduling permission request --- .../repositories/notifications_repository.dart | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/features/notes/data/repositories/notifications_repository.dart b/lib/features/notes/data/repositories/notifications_repository.dart index 81f0baa7..609daa54 100644 --- a/lib/features/notes/data/repositories/notifications_repository.dart +++ b/lib/features/notes/data/repositories/notifications_repository.dart @@ -76,12 +76,19 @@ class NotificationsRepository implements INotificationsRepository { } Future areNotificationsEnabled() async { - final bool granted = await flutterLocalNotificationsPlugin + final bool notificationAllowed = await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin>() ?.areNotificationsEnabled() ?? false; - return granted; + + final bool scheduleAllowed = await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + ?.canScheduleExactNotifications() ?? + false; + + return notificationAllowed && scheduleAllowed; } Future requestPermission() async { @@ -92,7 +99,10 @@ class NotificationsRepository implements INotificationsRepository { final bool grantedNotificationPermission = await androidImplementation?.requestNotificationsPermission() ?? false; - return grantedNotificationPermission; + final bool allowedSchedulingPermission = + await androidImplementation?.requestExactAlarmsPermission() ?? false; + + return grantedNotificationPermission && allowedSchedulingPermission; } @override