build method
Builds a new WebView.
Returns a Widget tree that embeds the created web view.
Implementation
@override
Widget build(BuildContext context) {
final initialSettings = params.initialSettings ?? InAppWebViewSettings();
_inferInitialSettings(initialSettings);
Map<String, dynamic> settingsMap =
(params.initialSettings != null ? initialSettings.toMap() : null) ??
// ignore: deprecated_member_use_from_same_package
params.initialOptions?.toMap() ??
initialSettings.toMap();
Map<String, dynamic> pullToRefreshSettings =
params.pullToRefreshController?.params.settings.toMap() ??
// ignore: deprecated_member_use_from_same_package
params.pullToRefreshController?.params.options.toMap() ??
PullToRefreshSettings(enabled: false).toMap();
if ((params.headlessWebView?.isRunning() ?? false) &&
params.keepAlive != null) {
final headlessId = params.headlessWebView?.id;
if (headlessId != null) {
// force keep alive id to match headless webview id
params.keepAlive?.id = headlessId;
}
}
var useHybridComposition = (params.initialSettings != null
? initialSettings.useHybridComposition
: params.initialOptions?.android.useHybridComposition) ??
true;
return PlatformViewLink(
key: params.key,
viewType: 'com.pichillilorenzo/flutter_inappwebview',
surfaceFactory: (
BuildContext context,
PlatformViewController controller,
) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
gestureRecognizers: params.gestureRecognizers ??
const <Factory<OneSequenceGestureRecognizer>>{},
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
);
},
onCreatePlatformView: (PlatformViewCreationParams params) {
return _createAndroidViewController(
hybridComposition: useHybridComposition,
id: params.id,
viewType: 'com.pichillilorenzo/flutter_inappwebview',
layoutDirection: this.params.layoutDirection ??
Directionality.maybeOf(context) ??
TextDirection.rtl,
creationParams: <String, dynamic>{
'initialUrlRequest': this.params.initialUrlRequest?.toMap(),
'initialFile': this.params.initialFile,
'initialData': this.params.initialData?.toMap(),
'initialSettings': settingsMap,
'contextMenu': this.params.contextMenu?.toMap() ?? {},
'windowId': this.params.windowId,
'headlessWebViewId':
this.params.headlessWebView?.isRunning() ?? false
? this.params.headlessWebView?.id
: null,
'initialUserScripts': this
.params
.initialUserScripts
?.map((e) => e.toMap())
.toList() ??
[],
'pullToRefreshSettings': pullToRefreshSettings,
'keepAliveId': this.params.keepAlive?.id
},
)
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
..addOnPlatformViewCreatedListener((id) => _onPlatformViewCreated(id))
..create();
},
);
}