搜索插件、代码仓与 APP 分类

插件详情v2.0.6

webview_cookie_manager

你是否变成了一个Cookie管理问题?这个包可以帮你解决。它包含了你一直在寻找的所有Cookie管理功能。

AndroidiOS
近 30 天下载
4300
喜欢数
85
Pub 分数
150

安装插件

flutter pub add webview_cookie_manager

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

webview_cookie_manager 包为使用 Android 和 iOS 上的 WebView 的 Flutter 应用提供了全面的 Cookie 管理功能。它使开发者能够读取、写入、删除和管理与 WebView 中渲染的网页内容相关的 Cookie,确保会话处理和身份验证的无缝衔接。该包直接与平台特定的 WebView 实现配合工作,跨平台提供一致的 API。非常适合需要持久登录状态或与基于 Web 的服务集成的应用。

适合场景

  • 在 WebView 中管理身份验证会话
  • 在应用重启后保持用户登录状态
  • 在 WebView 和后端服务之间同步 cookies
  • 处理第三方登录流程,例如 OAuth
  • 使用存储的 cookie 自动提交表单

主要特点

  • 跨平台的 Android 和 iOS Cookie 管理
  • 支持在网页视图中读取和写入 Cookie
  • 与平台 WebView 组件集成
  • 用于常见 cookie 操作的简单 API
  • Cookie 数据的安全存储

适合对象

  • 嵌入网页内容的应用程序
  • 认证密集型应用
  • Web服务集成
  • 单点登录 (SSO) 工作流程
  • 使用基于Web的后端的移动应用

使用建议

  • 需要适当的权限才能访问网页视图
  • 仅限网页视图特定的 cookie 上下文
  • 可能需要为复杂场景进行额外设置
  • 不适用于通用应用范围的 Cookie 管理
  • 取决于底层平台的 WebView 实现

原始 README

以下为关联源码仓库的 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

所属分类

源码仓库

使用此插件的项目