setSettings method

Future<void> setSettings(
  1. InAppWebViewSettings newSettings
)

Implementation

Future<void> setSettings(InAppWebViewSettings newSettings) async {
  Set<Sandbox> sandbox = getSandbox();

  if (newSettings.javaScriptEnabled != null &&
      settings!.javaScriptEnabled != newSettings.javaScriptEnabled) {
    if (!newSettings.javaScriptEnabled!) {
      sandbox.remove(Sandbox.ALLOW_SCRIPTS);
    } else {
      sandbox.add(Sandbox.ALLOW_SCRIPTS);
    }
  }

  if (settings!.iframeAllow != newSettings.iframeAllow) {
    iframe.allow = newSettings.iframeAllow ?? '';
  }
  if (settings!.iframeAllowFullscreen != newSettings.iframeAllowFullscreen) {
    iframe.allowFullscreen = newSettings.iframeAllowFullscreen ?? false;
  }
  if (settings!.iframeReferrerPolicy != newSettings.iframeReferrerPolicy) {
    iframe.referrerPolicy =
        newSettings.iframeReferrerPolicy?.toNativeValue() ?? '';
  }
  if (settings!.iframeName != newSettings.iframeName) {
    iframe.name = newSettings.iframeName ?? '';
  }
  if (settings!.iframeCsp != newSettings.iframeCsp) {
    iframe.csp = newSettings.iframeCsp;
  }
  if (settings!.iframeRole != newSettings.iframeRole) {
    iframe.role = newSettings.iframeRole;
  }
  if (settings!.iframeAriaHidden != newSettings.iframeAriaHidden) {
    iframe.ariaHidden = newSettings.iframeAriaHidden;
  }

  if (settings!.iframeSandbox != newSettings.iframeSandbox) {
    var sandbox = newSettings.iframeSandbox;
    if (sandbox != null && sandbox != Sandbox.ALLOW_ALL) {
      iframe.setAttribute(
          "sandbox", sandbox.map((e) => e.toNativeValue()).join(" "));
    } else if (sandbox == Sandbox.ALLOW_ALL) {
      iframe.removeAttribute("sandbox");
    }
  } else if (sandbox != Sandbox.values) {
    iframe.setAttribute(
        "sandbox", sandbox.map((e) => e.toNativeValue()).join(" "));
  }
  newSettings.iframeSandbox = sandbox;

  jsWebView?.setSettings(newSettings.toMap().jsify());

  settings = newSettings;
}