setSettings method
Future<void>
setSettings(
- 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!.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;
}