setCookie method

Future<bool> setCookie({
  1. required WebUri url,
  2. required String name,
  3. required String value,
  4. String path = "/",
  5. String? domain,
  6. int? expiresDate,
  7. int? maxAge,
  8. bool? isSecure,
  9. bool? isHttpOnly,
  10. HTTPCookieSameSitePolicy? sameSite,
  11. @Deprecated("Use webViewController instead") InAppWebViewController? iosBelow11WebViewController,
  12. InAppWebViewController? webViewController,
})

Sets a cookie for the given url. Any existing cookie with the same host, path and name will be replaced with the new cookie. The cookie being set will be ignored if it is expired.

The default value of path is "/".

The return value indicates whether the cookie was set successfully.

Officially Supported Platforms/Implementations:

Parameters - Officially Supported Platforms/Implementations:

  • url: all platforms
  • name: all platforms
  • value: all platforms
  • path: all platforms
  • domain: all platforms
  • expiresDate: all platforms
  • maxAge: all platforms
  • isSecure: all platforms
  • isHttpOnly: all platforms
  • sameSite: all platforms
  • webViewController:
    • macOS WKWebView
    • iOS WKWebView
    • Web <iframe> but requires same origin
    • Windows WebView2

Use the PlatformCookieManager.isMethodSupported method to check if this method is supported at runtime.

Implementation

Future<bool> setCookie({
  required WebUri url,
  required String name,
  required String value,
  String path = "/",
  String? domain,
  int? expiresDate,
  int? maxAge,
  bool? isSecure,
  bool? isHttpOnly,
  HTTPCookieSameSitePolicy? sameSite,
  @Deprecated("Use webViewController instead")
  InAppWebViewController? iosBelow11WebViewController,
  InAppWebViewController? webViewController,
}) => platform.setCookie(
  url: url,
  name: name,
  value: value,
  path: path,
  domain: domain,
  expiresDate: expiresDate,
  maxAge: maxAge,
  isSecure: isSecure,
  isHttpOnly: isHttpOnly,
  sameSite: sameSite,
  iosBelow11WebViewController: iosBelow11WebViewController?.platform,
  webViewController: webViewController?.platform,
);