setCookie method
- 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") PlatformInAppWebViewController? iosBelow11WebViewController,
- PlatformInAppWebViewController? 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:
- Android native WebView (Official API - CookieManager.setCookie)
- iOS (Official API - WKHTTPCookieStore.setCookie)
- MacOS (Official API - WKHTTPCookieStore.setCookie)
- Web
- Windows
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")
PlatformInAppWebViewController? iosBelow11WebViewController,
PlatformInAppWebViewController? webViewController}) {
throw UnimplementedError(
'setCookie is not implemented on the current platform');
}