FLUTTER ECOSYSTEM

fryette/webview_cookie_manager

fryette/webview_cookie_manager open-source repository details.

webview_cookie_manager 项目封面
Stars
66
Forks
87
最近推送(UTC)
2025年5月6日
项目状态
未归档
Yauhen Sampir GitHub avatar
GITHUB User

Yauhen Sampir ↗

Spain
语言SwiftDartJavaTypeScriptRubyKotlinObjective-C

此仓库发布的插件

使用的依赖

依赖清单 2 项
  • flutter{"sdk":"flutter"}
  • flutter_test开发依赖{"sdk":"flutter"}

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

展开 / 收起项目 README

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