Search packages, repositories and app categories

Package detailsv2.0.6

webview_cookie_manager

Have you been turned into a cookie management problem? This package can help. It has all of the cookie management functionality you have been looking for.

AndroidiOS
30-day downloads
4.3K
Likes
85
Pub points
150

Install package

flutter pub add webview_cookie_manager

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The webview_cookie_manager package provides comprehensive cookie management for Flutter apps using webviews on Android and iOS. It enables developers to read, write, delete, and manage cookies associated with web content rendered in webviews, ensuring seamless session handling and authentication. The package is designed to work directly with platform-specific webview implementations, offering a consistent API across platforms. Ideal for apps requiring persistent login states or integration with web-based services.

Use cases

  • Managing authentication sessions in webviews
  • Persisting user login state across app restarts
  • Syncing cookies between webview and backend services
  • Handling third-party login flows like OAuth
  • Automating form submissions with stored cookies

Key features

  • Cross-platform cookie management for Android and iOS
  • Support for reading and writing cookies in webviews
  • Integration with platform webview components
  • Simple API for common cookie operations
  • Secure storage of cookie data

Suitable for

  • Apps with embedded web content
  • Authentication-heavy applications
  • Web service integrations
  • Single sign-on (SSO) workflows
  • Mobile apps using web-based backends

Considerations

  • Requires proper permissions for webview access
  • Limited to webview-specific cookie contexts
  • May require additional setup for complex scenarios
  • Not suitable for general app-wide cookie management
  • Dependent on underlying platform webview implementation

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Webview Cookie Manager

pub package

A flutter library to manager your web cookies for Android (API level 9+) and iOS (11+).

The cookies stores and retrieves using the httpCookieStore for iOS and CookieManager for Android.

Get started iOS

Set minimum version for iOS to 11.0

Usage

The WebCookieManager can be used directly or together with webview_flutter.

Get cookies
final cookieManager = WebviewCookieManager();

final gotCookies = await cookieManager.getCookies('https://youtube.com');
for (var item in gotCookies) {
  print(item);
}
Set a cookie
await cookieManager.setCookies([
              Cookie('cookieName', 'cookieValue')
                ..domain = 'youtube.com'
                ..expires = DateTime.now().add(Duration(days: 10))
                ..httpOnly = false
            ]);
Check is any cookie available
await cookieManager.hasCookies();
Remove a cookie
await cookieManager.removeCookie();
Clear cookies
await cookieManager.clearCookies();
Domain attribute

Domain attribute is not required according to RFC, but it is important to remember that empty domain causes undefined behavior. So it is highly reccommended to specify it this this way:

final cookie = Cookie('cookieName', 'cookieValue')..domain = 'youtube.com';
Secure attribute

If you see the error Strict Secure Cookie policy does not allow setting a secure cookie for http://your-domain.net/ for apps targeting >= R. Please either use the 'https:' scheme for this URL or omit the 'Secure' directive in the cookie value. Then you need to set the origin while setting the cookie, in that case setting the domain is not required.

final cookies = <Cookie>[];
// Add your cookie with secure flag to the array
cookieManager.setCookies(cookies, origin: 'https://your-domain.net')

Troubleshooting on iOS

  1. Set minimum target iOS version to 11 (see also #17)
  2. If you are using Objective C, check that PodFile have a flag use_frameworks (see also #4)
target 'Runner' do
  use_frameworks!
  use_modular_headers!
  ..........
end

Categories

Source repository

Projects using this package