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 "/".

webViewController could be used if you need to set a session-only cookie using JavaScript (so isHttpOnly cannot be set, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies) on the current URL of the WebView managed by that controller when you need to target iOS below 11, MacOS below 10.13 and Web platform. In this case the url parameter is ignored.

The return value indicates whether the cookie was set successfully. Note that it will return always true for Web platform, iOS below 11.0 and MacOS below 10.13.

NOTE for iOS below 11.0 and MacOS below 10.13: If webViewController is null or JavaScript is disabled for it, it will try to use a PlatformHeadlessInAppWebView to set the cookie (session-only cookie won't work! In that case, you should set also expiresDate or maxAge).

NOTE for Web: this method will have effect only if the iframe has the same origin. If webViewController is null or JavaScript is disabled for it, it will try to use a PlatformHeadlessInAppWebView to set the cookie (session-only cookie won't work! In that case, you should set also expiresDate or maxAge).

Officially Supported Platforms/Implementations:

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);