dispose method
Disposes the notification manager and cleans up resources.
Implementation
Future<NotificationFailure?> dispose() async {
try {
if (!_isInitialized) return null;
// Cancel Firebase foreground subscription
await _firebaseForegroundSubscription?.cancel();
_firebaseForegroundSubscription = null;
// Dispose foreground notification manager
final ForegroundNotificationManager? foregroundManager =
_foregroundManager;
if (foregroundManager != null) {
final NotificationFailure? foregroundError = foregroundManager
.dispose();
if (foregroundError != null) {
safeDebugLog(
'Foreground manager disposal failed: ${foregroundError.message}',
);
}
}
// Dispose both repositories
final NotificationFailure? firebaseError = await _firebaseRepository
.dispose();
final NotificationFailure? localError = await _localRepository.dispose();
_isInitialized = false;
_userPreferences = null;
safeDebugLog('Comprehensive notification manager disposed');
// Return the first error if any
return firebaseError ?? localError;
} catch (e, stackTrace) {
safeDebugLog('Failed to dispose notification manager: $e');
return NotificationFailure.unknown(
details: e.toString(),
stackTrace: stackTrace,
);
}
}