scheduleNotification method
Schedules a notification for future delivery
Implementation
Future<void> scheduleNotification(
MCPNotification notification,
DateTime scheduledTime,
) async {
if (!_isInitialized) {
throw StateError(
'NotificationManager must be initialized before scheduling notifications');
}
try {
// Store the notification with scheduled time
final scheduledNotification = notification.copyWith(
scheduledTime: scheduledTime,
);
_activeNotifications[notification.id] = scheduledNotification;
// Schedule based on type
switch (notification.type) {
case NotificationType.local:
case NotificationType.system:
await _scheduleSystemNotification(scheduledNotification);
break;
case NotificationType.inApp:
// In-app notifications are handled differently
await _scheduleInAppNotification(scheduledNotification);
break;
}
// Notify listeners
_notifyListeners(NotificationEvent.scheduled, scheduledNotification);
if (enableDebugMode) {
debugPrint(
'NotificationManager: Scheduled notification "${notification.id}" for $scheduledTime');
}
} catch (error) {
if (enableDebugMode) {
debugPrint(
'NotificationManager: Error scheduling notification "${notification.id}": $error');
}
rethrow;
}
}