搜尋套件、儲存庫與 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

所屬分類

原始碼儲存庫

使用此套件的專案