build method

  1. @override
Widget build(
  1. BuildContext context
)

Builds a new WebView.

Returns a Widget tree that embeds the created web view.

Implementation

@override
Widget build(BuildContext context) {
  _trySetDefaultOnShowCustomWidgetCallbacks(context);
  return PlatformViewLink(
    // Setting a default key using `params` ensures the `PlatformViewLink`
    // recreates the PlatformView when changes are made.
    key: _androidParams.key ??
        ValueKey<AndroidWebViewWidgetCreationParams>(
            params as AndroidWebViewWidgetCreationParams),
    viewType: 'plugins.flutter.io/webview',
    surfaceFactory: (
      BuildContext context,
      PlatformViewController controller,
    ) {
      return AndroidViewSurface(
        controller: controller as AndroidViewController,
        gestureRecognizers: _androidParams.gestureRecognizers,
        hitTestBehavior: PlatformViewHitTestBehavior.opaque,
      );
    },
    onCreatePlatformView: (PlatformViewCreationParams params) {
      return _initAndroidView(
        params,
        displayWithHybridComposition:
            _androidParams.displayWithHybridComposition,
        platformViewsServiceProxy: _androidParams.platformViewsServiceProxy,
        view:
            (_androidParams.controller as AndroidWebViewController)._webView,
        instanceManager: _androidParams.instanceManager,
        layoutDirection: _androidParams.layoutDirection,
      )
        ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
        ..create();
    },
  );
}