initialize method
Initializes the cookie consent manager.
This method:
- Loads saved preferences if they exist
- Sets up initial consent state
- Handles any initialization errors
Implementation
Future<void> initialize() async {
if (_isInitialized) return;
try {
final savedPreferences = await _platform.getCookiePreferences();
if (savedPreferences != null) {
_cookiePreferences = Map<String, bool>.from(savedPreferences);
_hasConsent = true;
_showBanner = false;
} else {
_showBanner = true;
}
_bannerVisibilityNotifier.value = _showBanner;
_isInitialized = true;
_lastError = null;
} catch (e) {
_lastError = 'Failed to initialize cookie consent: $e';
debugPrint(_lastError);
_showBanner = true;
_bannerVisibilityNotifier.value = true;
}
}