FlutterCookieConsent class

Main class for managing cookie consent in a Flutter application.

This class provides functionality to:

  • Initialize and manage cookie preferences
  • Display a cookie consent banner
  • Save user preferences
  • Check consent status

Example:

final cookieConsent = FlutterCookieConsent();
await cookieConsent.initialize();

if (cookieConsent.shouldShowBanner) {
  // Show the banner
  cookieConsent.createBanner(
    context: context,
    title: 'Cookie Consent',
    message: 'We use cookies...',
  );
}

Constructors

FlutterCookieConsent()
factory

Properties

bannerVisibilityNotifier ValueNotifier<bool>
Getter for banner visibility notifier
no setter
hasConsent bool
Returns whether user has given consent
no setter
hashCode int
The hash code for this object.
no setterinherited
lastError String?
Getter for last error message
no setter
preferences Map<String, bool>
Returns current cookie preferences
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shouldShowBanner bool
Returns whether banner should be shown
no setter

Methods

createBanner({required BuildContext context, String? title, String? message, String? acceptButtonText, String? declineButtonText, String? settingsButtonText, bool showSettings = true, CookieConsentStyle? style, dynamic onAccept(bool)?, dynamic onDecline(bool)?, dynamic onSettings()?, BannerPosition position = BannerPosition.top}) Widget
Creates and returns a cookie consent banner widget.
initialize() Future<void>
Initializes the cookie consent manager.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
savePreferences(Map<String, bool> preferences) Future<void>
Saves user's cookie preferences.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited