deleteCookies method Null safety

Future<void> deleteCookies(
  1. {required Uri url,
  2. String domain = "",
  3. String path = "/",
  4. InAppWebViewController? iosBelow11WebViewController}

Removes all cookies for the given url, domain and path.

The default value of path is "/". If domain is empty, its default value will be the domain name of url.

iosBelow11WebViewController is used for deleting the cookies (also session-only cookies) using JavaScript (cookies with isHttpOnly enabled cannot be deleted, see: from the current context of the WebView managed by that controller when you need to target iOS below 11. JavaScript must be enabled in order to work. In this case the url parameter is ignored.

NOTE for iOS below 11.0: If iosBelow11WebViewController is null or JavaScript is disabled for it, it will try to use a HeadlessInAppWebView to delete the cookies (session-only cookies and cookies with isHttpOnly enabled won't be deleted!).


Future<void> deleteCookies(
    {required Uri url,
    String domain = "",
    String path = "/",
    InAppWebViewController? iosBelow11WebViewController}) async {
  if (domain.isEmpty) domain = _getDomainName(url);


  if (defaultTargetPlatform == TargetPlatform.iOS) {
    var platformUtil = PlatformUtil();
    var version = double.tryParse(await platformUtil.getSystemVersion());
    if (version != null && version < 11.0) {
      List<Cookie> cookies = await _getCookiesWithJavaScript(
          url: url, webViewController: iosBelow11WebViewController);
      for (var i = 0; i < cookies.length; i++) {
        await _setCookieWithJavaScript(
            url: url,
            name: cookies[i].name,
            value: "",
            path: path,
            domain: domain,
            maxAge: -1,
            webViewController: iosBelow11WebViewController);

  Map<String, dynamic> args = <String, dynamic>{};
  args.putIfAbsent('url', () => url.toString());
  args.putIfAbsent('domain', () => domain);
  args.putIfAbsent('path', () => path);
  await _channel.invokeMethod('deleteCookies', args);