build method
- required BuildContext context,
- required CreationParams creationParams,
- required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler,
- required JavascriptChannelRegistry javascriptChannelRegistry,
- WebViewPlatformCreatedCallback? onWebViewPlatformCreated,
- Set<
Factory< ? gestureRecognizers,OneSequenceGestureRecognizer> >
Builds a new WebView.
Returns a Widget tree that embeds the created webview.
creationParams
are the initial parameters used to setup the webview.
webViewPlatformHandler
will be used for handling callbacks that are made by the created
WebViewPlatformController
.
onWebViewPlatformCreated
will be invoked after the platform specific WebViewPlatformController
implementation is created with the WebViewPlatformController
instance as a parameter.
gestureRecognizers
specifies which gestures should be consumed by the web view.
It is possible for other gesture recognizers to be competing with the web view on pointer
events, e.g if the web view is inside a ListView the ListView will want to handle
vertical drags. The web view will claim gestures that are recognized by any of the
recognizers on this list.
When gestureRecognizers
is empty or null, the web view will only handle pointer events for gestures that
were not claimed by any other gesture recognizer.
webViewPlatformHandler
must not be null.
Implementation
@override
Widget build({
required BuildContext context,
required CreationParams creationParams,
required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler,
required JavascriptChannelRegistry javascriptChannelRegistry,
WebViewPlatformCreatedCallback? onWebViewPlatformCreated,
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
}) {
return WebViewAndroidWidget(
useHybridComposition: false,
creationParams: creationParams,
callbacksHandler: webViewPlatformCallbacksHandler,
javascriptChannelRegistry: javascriptChannelRegistry,
onBuildWidget: (WebViewAndroidPlatformController controller) {
return GestureDetector(
// We prevent text selection by intercepting the long press event.
// This is a temporary stop gap due to issues with text selection on Android:
// https://github.com/flutter/flutter/issues/24585 - the text selection
// dialog is not responding to touch events.
// https://github.com/flutter/flutter/issues/24584 - the text selection
// handles are not showing.
// TODO(amirh): remove this when the issues above are fixed.
onLongPress: () {},
excludeFromSemantics: true,
child: AndroidView(
viewType: 'plugins.flutter.io/webview',
onPlatformViewCreated: (int id) {
if (onWebViewPlatformCreated != null) {
onWebViewPlatformCreated(controller);
}
},
gestureRecognizers: gestureRecognizers,
layoutDirection:
Directionality.maybeOf(context) ?? TextDirection.rtl,
creationParams:
InstanceManager.instance.getInstanceId(controller.webView),
creationParamsCodec: const StandardMessageCodec(),
),
);
},
);
}