Skip to main content
Version: 5.x.x

Cookie Manager

To manage WebView cookies, you can use the CookieManager class, which implements a singleton object (shared instance).

On Android, it is implemented using the CookieManager class. On iOS, it is implemented using the WKHTTPCookieStore class.

Basic Usage

Note for iOS below 11.0 (LIMITED SUPPORT!)

In this case, almost all of the methods (CookieManager.deleteAllCookies and IOSCookieManager.getAllCookies are not supported!) has been implemented using JavaScript because there is no other way to work with them on iOS below 11.0. Check here for JavaScript restrictions.

Example:

// get the CookieManager instance
CookieManager cookieManager = CookieManager.instance();

// set the expiration date for the cookie in milliseconds
final expiresDate = DateTime.now().add(Duration(days: 3)).millisecondsSinceEpoch;
final url = Uri.parse("https://flutter.dev/");

// set the cookie
await cookieManager.setCookie(
url: url,
name: "myCookie",
value: "myValue",
expiresDate: expiresDate,
isSecure: true,
);

// get cookies
List<Cookie> cookies = await cookieManager.getCookies(url: url);

// get a cookie
Cookie? cookie = await cookieManager.getCookie(url: url, name: "myCookie");

// delete a cookie
await cookieManager.deleteCookie(url: url, name: "myCookie");

// delete cookies
await cookieManager.deleteCookies(url: url, domain: ".flutter.dev");