feature/notification-date #49

Merged
v4l3n71n merged 5 commits from feature/notification-date into main 2025-08-27 21:53:18 +00:00
8 changed files with 189 additions and 0 deletions
Showing only changes of commit 5d9802d56e - Show all commits

View File

@@ -19,6 +19,28 @@ class NotificationService {
);
await _notificationsPlugin.initialize(initSettings);
// Demande les permissions au lancement
await requestPermissions();
}
/// Demander les permissions (Android 13+ et iOS)
static Future<void> requestPermissions() async {
// Android 13+
final androidImplementation =
_notificationsPlugin.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>();
await androidImplementation?.requestNotificationsPermission();
// iOS
final iosImplementation =
_notificationsPlugin.resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>();
await iosImplementation?.requestPermissions(
alert: true,
badge: true,
sound: true,
);
}
/// Planifie une notification 1h avant lévènement
@@ -42,24 +64,26 @@ class NotificationService {
tz.TZDateTime.from(scheduledDate, tz.local),
const NotificationDetails(
android: AndroidNotificationDetails(
'events_channel', // id du canal
'Évènements', // nom du canal
'events_channel',
'Évènements',
channelDescription: 'Notifications des évènements favoris',
importance: Importance.high,
priority: Priority.high,
),
iOS: DarwinNotificationDetails(),
),
androidScheduleMode: AndroidScheduleMode.inexactAllowWhileIdle,
androidScheduleMode: AndroidScheduleMode
.inexactAllowWhileIdle, // évite l'erreur Exact Alarm
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.dateAndTime,
);
}
/// Notification immédiate (debug)
static Future<void> showTestNotification() async {
await _notificationsPlugin.show(
0, // id arbitraire
0,
"Test Notification",
"Ceci est une notification de debug",
const NotificationDetails(