buildWebView method
Builds WebView.
JavaScript is only enabled if webViewJs is turned on
AND sandbox restrictions are unset (no sandbox
attribute)
or allow-scripts
is explicitly allowed.
Implementation
Widget? buildWebView(
BuildMetadata meta,
String url, {
double? height,
Iterable<String>? sandbox,
double? width,
}) {
if (!webView) {
return buildWebViewLinkOnly(meta, url);
}
final dimensOk = height != null && height > 0 && width != null && width > 0;
final js = webViewJs &&
(sandbox == null ||
sandbox.contains(kAttributeIframeSandboxAllowScripts));
return WebView(
url,
aspectRatio: dimensOk ? width / height : 16 / 9,
autoResize: !dimensOk && js,
debuggingEnabled: webViewDebuggingEnabled,
interceptNavigationRequest: (newUrl) {
if (newUrl == url) {
return false;
}
gestureTapCallback(newUrl)?.call();
return true;
},
js: js,
mediaPlaybackAlwaysAllow: webViewMediaPlaybackAlwaysAllow,
onAndroidHideCustomWidget: webViewOnAndroidHideCustomWidget,
onAndroidShowCustomWidget: webViewOnAndroidShowCustomWidget,
userAgent: webViewUserAgent,
);
}