buildWebView method

Widget? buildWebView(
  1. BuildMetadata meta,
  2. String url, {
  3. double? height,
  4. Iterable<String>? sandbox,
  5. double? width,
})

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,
  );
}