iosWebViewFix/lib/src/in_app_webview/in_app_webview.dart

698 lines
25 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'dart:collection';
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/gestures.dart';
2022-04-21 21:14:51 +00:00
import '../web/web_platform_manager.dart';
import '../context_menu.dart';
import '../types/main.dart';
import 'webview.dart';
import 'in_app_webview_controller.dart';
2022-04-19 23:31:14 +00:00
import 'in_app_webview_settings.dart';
import '../pull_to_refresh/main.dart';
///Flutter Widget for adding an **inline native WebView** integrated in the flutter widget tree.
///
///**Supported Platforms/Implementations**:
///- Android native WebView
///- iOS
///- Web
class InAppWebView extends StatefulWidget implements WebView {
/// `gestureRecognizers` specifies which gestures should be consumed by the WebView.
/// 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.
final Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers;
///The window id of a [CreateWindowAction.windowId].
2022-04-21 21:14:51 +00:00
@override
final int? windowId;
const InAppWebView({
Key? key,
this.windowId,
this.initialUrlRequest,
this.initialFile,
this.initialData,
2022-04-19 23:31:14 +00:00
@Deprecated('Use initialSettings instead') this.initialOptions,
this.initialSettings,
this.initialUserScripts,
this.pullToRefreshController,
this.implementation = WebViewImplementation.NATIVE,
this.contextMenu,
this.onWebViewCreated,
this.onLoadStart,
this.onLoadStop,
@Deprecated("Use onReceivedError instead") this.onLoadError,
this.onReceivedError,
@Deprecated("Use onReceivedHttpError instead") this.onLoadHttpError,
this.onReceivedHttpError,
this.onConsoleMessage,
this.onProgressChanged,
this.shouldOverrideUrlLoading,
this.onLoadResource,
this.onScrollChanged,
2022-04-19 23:31:14 +00:00
@Deprecated('Use onDownloadStartRequest instead') this.onDownloadStart,
2022-04-17 14:19:31 +00:00
this.onDownloadStartRequest,
this.onLoadResourceCustomScheme,
this.onCreateWindow,
this.onCloseWindow,
this.onJsAlert,
this.onJsConfirm,
this.onJsPrompt,
this.onReceivedHttpAuthRequest,
this.onReceivedServerTrustAuthRequest,
this.onReceivedClientCertRequest,
this.onFindResultReceived,
this.shouldInterceptAjaxRequest,
this.onAjaxReadyStateChange,
this.onAjaxProgress,
this.shouldInterceptFetchRequest,
this.onUpdateVisitedHistory,
this.onPrint,
this.onLongPressHitTestResult,
2020-05-23 17:33:54 +00:00
this.onEnterFullscreen,
this.onExitFullscreen,
this.onPageCommitVisible,
this.onTitleChanged,
this.onWindowFocus,
this.onWindowBlur,
this.onOverScrolled,
this.onZoomScaleChanged,
2022-04-19 23:31:14 +00:00
@Deprecated('Use onSafeBrowsingHit instead') this.androidOnSafeBrowsingHit,
this.onSafeBrowsingHit,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onPermissionRequest instead')
this.androidOnPermissionRequest,
2022-04-19 23:31:14 +00:00
this.onPermissionRequest,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onGeolocationPermissionsShowPrompt instead')
this.androidOnGeolocationPermissionsShowPrompt,
2022-04-19 23:31:14 +00:00
this.onGeolocationPermissionsShowPrompt,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onGeolocationPermissionsHidePrompt instead')
this.androidOnGeolocationPermissionsHidePrompt,
2022-04-19 23:31:14 +00:00
this.onGeolocationPermissionsHidePrompt,
2022-04-20 01:05:46 +00:00
@Deprecated('Use shouldInterceptRequest instead')
this.androidShouldInterceptRequest,
2022-04-19 23:31:14 +00:00
this.shouldInterceptRequest,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onRenderProcessGone instead')
this.androidOnRenderProcessGone,
2022-04-19 23:31:14 +00:00
this.onRenderProcessGone,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onRenderProcessResponsive instead')
this.androidOnRenderProcessResponsive,
2022-04-19 23:31:14 +00:00
this.onRenderProcessResponsive,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onRenderProcessUnresponsive instead')
this.androidOnRenderProcessUnresponsive,
2022-04-19 23:31:14 +00:00
this.onRenderProcessUnresponsive,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onFormResubmission instead')
this.androidOnFormResubmission,
2022-04-19 23:31:14 +00:00
this.onFormResubmission,
@Deprecated('Use onZoomScaleChanged instead') this.androidOnScaleChanged,
@Deprecated('Use onReceivedIcon instead') this.androidOnReceivedIcon,
this.onReceivedIcon,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onReceivedTouchIconUrl instead')
this.androidOnReceivedTouchIconUrl,
2022-04-19 23:31:14 +00:00
this.onReceivedTouchIconUrl,
@Deprecated('Use onJsBeforeUnload instead') this.androidOnJsBeforeUnload,
this.onJsBeforeUnload,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onReceivedLoginRequest instead')
this.androidOnReceivedLoginRequest,
2022-04-19 23:31:14 +00:00
this.onReceivedLoginRequest,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onWebContentProcessDidTerminate instead')
this.iosOnWebContentProcessDidTerminate,
2022-04-19 23:31:14 +00:00
this.onWebContentProcessDidTerminate,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onDidReceiveServerRedirectForProvisionalNavigation instead')
this.iosOnDidReceiveServerRedirectForProvisionalNavigation,
2022-04-19 23:31:14 +00:00
this.onDidReceiveServerRedirectForProvisionalNavigation,
2022-04-20 01:05:46 +00:00
@Deprecated('Use onNavigationResponse instead')
this.iosOnNavigationResponse,
2022-04-19 23:31:14 +00:00
this.onNavigationResponse,
2022-04-20 01:05:46 +00:00
@Deprecated('Use shouldAllowDeprecatedTLS instead')
this.iosShouldAllowDeprecatedTLS,
2022-04-19 23:31:14 +00:00
this.shouldAllowDeprecatedTLS,
this.gestureRecognizers,
}) : super(key: key);
@override
_InAppWebViewState createState() => _InAppWebViewState();
2022-04-19 23:31:14 +00:00
///Use [onGeolocationPermissionsHidePrompt] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onGeolocationPermissionsHidePrompt instead')
final void Function(InAppWebViewController controller)?
androidOnGeolocationPermissionsHidePrompt;
2022-04-19 23:31:14 +00:00
///Use [onGeolocationPermissionsShowPrompt] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onGeolocationPermissionsShowPrompt instead')
final Future<GeolocationPermissionShowPromptResponse?> Function(
InAppWebViewController controller, String origin)?
androidOnGeolocationPermissionsShowPrompt;
2022-04-19 23:31:14 +00:00
///Use [onPermissionRequest] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onPermissionRequest instead')
final Future<PermissionRequestResponse?> Function(
InAppWebViewController controller,
String origin,
List<String> resources)? androidOnPermissionRequest;
2022-04-19 23:31:14 +00:00
///Use [onSafeBrowsingHit] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onSafeBrowsingHit instead')
2021-02-22 22:54:09 +00:00
final Future<SafeBrowsingResponse?> Function(
InAppWebViewController controller,
Uri url,
SafeBrowsingThreat? threatType)? androidOnSafeBrowsingHit;
@override
final InAppWebViewInitialData? initialData;
@override
final String? initialFile;
2022-04-19 23:31:14 +00:00
///Use [initialSettings] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use initialSettings instead')
final InAppWebViewGroupOptions? initialOptions;
2022-04-19 23:31:14 +00:00
@override
final InAppWebViewSettings? initialSettings;
@override
final URLRequest? initialUrlRequest;
@override
final WebViewImplementation implementation;
@override
final UnmodifiableListView<UserScript>? initialUserScripts;
@override
final PullToRefreshController? pullToRefreshController;
@override
final ContextMenu? contextMenu;
@override
final void Function(InAppWebViewController controller, Uri? url)?
onPageCommitVisible;
@override
final void Function(InAppWebViewController controller, String? title)?
2020-06-29 14:37:36 +00:00
onTitleChanged;
2022-04-19 23:31:14 +00:00
///Use [onDidReceiveServerRedirectForProvisionalNavigation] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onDidReceiveServerRedirectForProvisionalNavigation instead')
final void Function(InAppWebViewController controller)?
iosOnDidReceiveServerRedirectForProvisionalNavigation;
2022-04-19 23:31:14 +00:00
///Use [onWebContentProcessDidTerminate] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onWebContentProcessDidTerminate instead')
final void Function(InAppWebViewController controller)?
iosOnWebContentProcessDidTerminate;
2022-04-19 23:31:14 +00:00
///Use [onNavigationResponse] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onNavigationResponse instead')
2021-02-22 22:54:09 +00:00
final Future<IOSNavigationResponseAction?> Function(
InAppWebViewController controller,
IOSWKNavigationResponse navigationResponse)? iosOnNavigationResponse;
2022-04-19 23:31:14 +00:00
///Use [shouldAllowDeprecatedTLS] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use shouldAllowDeprecatedTLS instead')
2021-02-22 22:54:09 +00:00
final Future<IOSShouldAllowDeprecatedTLSAction?> Function(
InAppWebViewController controller,
URLAuthenticationChallenge challenge)? iosShouldAllowDeprecatedTLS;
@override
final Future<AjaxRequestAction> Function(
InAppWebViewController controller, AjaxRequest ajaxRequest)?
onAjaxProgress;
@override
final Future<AjaxRequestAction?> Function(
InAppWebViewController controller, AjaxRequest ajaxRequest)?
onAjaxReadyStateChange;
@override
final void Function(
InAppWebViewController controller, ConsoleMessage consoleMessage)?
onConsoleMessage;
@override
final Future<bool?> Function(InAppWebViewController controller,
CreateWindowAction createWindowAction)? onCreateWindow;
@override
final void Function(InAppWebViewController controller)? onCloseWindow;
@override
final void Function(InAppWebViewController controller)? onWindowFocus;
@override
final void Function(InAppWebViewController controller)? onWindowBlur;
2022-04-19 23:31:14 +00:00
///Use [onReceivedIcon] instead
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onReceivedIcon instead')
final void Function(InAppWebViewController controller, Uint8List icon)?
2020-06-29 14:37:36 +00:00
androidOnReceivedIcon;
2022-04-19 23:31:14 +00:00
///Use [onReceivedTouchIconUrl] instead
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onReceivedTouchIconUrl instead')
2020-06-29 14:37:36 +00:00
final void Function(
InAppWebViewController controller, Uri url, bool precomposed)?
2020-06-29 14:37:36 +00:00
androidOnReceivedTouchIconUrl;
2022-04-17 14:19:31 +00:00
///Use [onDownloadStartRequest] instead
2022-04-19 23:31:14 +00:00
@Deprecated('Use onDownloadStartRequest instead')
@override
2022-04-17 14:19:31 +00:00
final void Function(InAppWebViewController controller, Uri url)?
onDownloadStart;
2022-04-17 14:19:31 +00:00
@override
2022-04-18 22:42:57 +00:00
final void Function(InAppWebViewController controller,
DownloadStartRequest downloadStartRequest)? onDownloadStartRequest;
2022-04-17 14:19:31 +00:00
@override
final void Function(InAppWebViewController controller, int activeMatchOrdinal,
int numberOfMatches, bool isDoneCounting)? onFindResultReceived;
@override
final Future<JsAlertResponse?> Function(
InAppWebViewController controller, JsAlertRequest jsAlertRequest)?
2020-06-29 14:37:36 +00:00
onJsAlert;
@override
final Future<JsConfirmResponse?> Function(
InAppWebViewController controller, JsConfirmRequest jsConfirmRequest)?
2020-06-29 14:37:36 +00:00
onJsConfirm;
@override
final Future<JsPromptResponse?> Function(
InAppWebViewController controller, JsPromptRequest jsPromptRequest)?
2020-06-29 14:37:36 +00:00
onJsPrompt;
///Use [onReceivedError] instead.
@Deprecated("Use onReceivedError instead")
@override
final void Function(InAppWebViewController controller, Uri? url, int code,
String message)? onLoadError;
@override
final void Function(InAppWebViewController controller,
WebResourceRequest request, WebResourceError error)? onReceivedError;
///Use [onReceivedHttpError] instead.
@Deprecated("Use onReceivedHttpError instead")
@override
final void Function(InAppWebViewController controller, Uri? url,
int statusCode, String description)? onLoadHttpError;
@override
final void Function(
InAppWebViewController controller,
WebResourceRequest request,
WebResourceResponse errorResponse)? onReceivedHttpError;
@override
final void Function(
InAppWebViewController controller, LoadedResource resource)?
onLoadResource;
@override
final Future<CustomSchemeResponse?> Function(
2021-02-22 22:54:09 +00:00
InAppWebViewController controller, Uri url)? onLoadResourceCustomScheme;
@override
2021-02-22 22:54:09 +00:00
final void Function(InAppWebViewController controller, Uri? url)? onLoadStart;
@override
final void Function(InAppWebViewController controller, Uri? url)? onLoadStop;
@override
final void Function(InAppWebViewController controller,
InAppWebViewHitTestResult hitTestResult)? onLongPressHitTestResult;
@override
final void Function(InAppWebViewController controller, Uri? url)? onPrint;
@override
final void Function(InAppWebViewController controller, int progress)?
onProgressChanged;
@override
2021-02-22 22:54:09 +00:00
final Future<ClientCertResponse?> Function(InAppWebViewController controller,
URLAuthenticationChallenge challenge)? onReceivedClientCertRequest;
@override
2021-02-22 22:54:09 +00:00
final Future<HttpAuthResponse?> Function(InAppWebViewController controller,
URLAuthenticationChallenge challenge)? onReceivedHttpAuthRequest;
@override
final Future<ServerTrustAuthResponse?> Function(
2021-02-22 22:54:09 +00:00
InAppWebViewController controller,
URLAuthenticationChallenge challenge)? onReceivedServerTrustAuthRequest;
@override
final void Function(InAppWebViewController controller, int x, int y)?
onScrollChanged;
@override
final void Function(
2022-04-19 23:31:14 +00:00
InAppWebViewController controller, Uri? url, bool? isReload)?
onUpdateVisitedHistory;
@override
final void Function(InAppWebViewController controller)? onWebViewCreated;
@override
final Future<AjaxRequest?> Function(
InAppWebViewController controller, AjaxRequest ajaxRequest)?
shouldInterceptAjaxRequest;
@override
final Future<FetchRequest?> Function(
InAppWebViewController controller, FetchRequest fetchRequest)?
shouldInterceptFetchRequest;
@override
final Future<NavigationActionPolicy?> Function(
InAppWebViewController controller, NavigationAction navigationAction)?
shouldOverrideUrlLoading;
2020-05-23 17:33:54 +00:00
@override
final void Function(InAppWebViewController controller)? onEnterFullscreen;
2020-05-23 17:33:54 +00:00
@override
final void Function(InAppWebViewController controller)? onExitFullscreen;
@override
2021-03-22 15:39:58 +00:00
final void Function(InAppWebViewController controller, int x, int y,
bool clampedX, bool clampedY)? onOverScrolled;
@override
final void Function(
InAppWebViewController controller, double oldScale, double newScale)?
onZoomScaleChanged;
2022-04-19 23:31:14 +00:00
///Use [shouldInterceptRequest] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use shouldInterceptRequest instead')
final Future<WebResourceResponse?> Function(
InAppWebViewController controller, WebResourceRequest request)?
androidShouldInterceptRequest;
2022-04-19 23:31:14 +00:00
///Use [onRenderProcessUnresponsive] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onRenderProcessUnresponsive instead')
final Future<WebViewRenderProcessAction?> Function(
InAppWebViewController controller, Uri? url)?
androidOnRenderProcessUnresponsive;
2022-04-19 23:31:14 +00:00
///Use [onRenderProcessResponsive] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onRenderProcessResponsive instead')
final Future<WebViewRenderProcessAction?> Function(
InAppWebViewController controller, Uri? url)?
androidOnRenderProcessResponsive;
2022-04-19 23:31:14 +00:00
///Use [onRenderProcessGone] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onRenderProcessGone instead')
final void Function(
InAppWebViewController controller, RenderProcessGoneDetail detail)?
androidOnRenderProcessGone;
2022-04-19 23:31:14 +00:00
///Use [onFormResubmission] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onFormResubmission instead')
final Future<FormResubmissionAction?> Function(
InAppWebViewController controller, Uri? url)? androidOnFormResubmission;
///Use [onZoomScaleChanged] instead.
2022-04-19 23:31:14 +00:00
@Deprecated('Use onZoomScaleChanged instead')
@override
final void Function(
InAppWebViewController controller, double oldScale, double newScale)?
androidOnScaleChanged;
2022-04-19 23:31:14 +00:00
///Use [onJsBeforeUnload] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onJsBeforeUnload instead')
final Future<JsBeforeUnloadResponse?> Function(
2020-06-29 14:37:36 +00:00
InAppWebViewController controller,
JsBeforeUnloadRequest jsBeforeUnloadRequest)? androidOnJsBeforeUnload;
2022-04-19 23:31:14 +00:00
///Use [onReceivedLoginRequest] instead.
@override
2022-04-19 23:31:14 +00:00
@Deprecated('Use onReceivedLoginRequest instead')
2020-06-29 14:37:36 +00:00
final void Function(
InAppWebViewController controller, LoginRequest loginRequest)?
2020-06-29 14:37:36 +00:00
androidOnReceivedLoginRequest;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final void Function(InAppWebViewController controller)?
onDidReceiveServerRedirectForProvisionalNavigation;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final Future<FormResubmissionAction?> Function(
InAppWebViewController controller, Uri? url)? onFormResubmission;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final void Function(InAppWebViewController controller)?
onGeolocationPermissionsHidePrompt;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final Future<GeolocationPermissionShowPromptResponse?> Function(
InAppWebViewController controller, String origin)?
onGeolocationPermissionsShowPrompt;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final Future<JsBeforeUnloadResponse?> Function(
InAppWebViewController controller,
JsBeforeUnloadRequest jsBeforeUnloadRequest)? onJsBeforeUnload;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final Future<NavigationResponseAction?> Function(
InAppWebViewController controller,
NavigationResponse navigationResponse)? onNavigationResponse;
2022-04-19 23:31:14 +00:00
@override
final Future<PermissionResponse?> Function(InAppWebViewController controller,
2022-04-21 10:20:48 +00:00
PermissionRequest permissionRequest)? onPermissionRequest;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final void Function(InAppWebViewController controller, Uint8List icon)?
onReceivedIcon;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final void Function(
InAppWebViewController controller, LoginRequest loginRequest)?
onReceivedLoginRequest;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final void Function(
InAppWebViewController controller, Uri url, bool precomposed)?
onReceivedTouchIconUrl;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final void Function(
InAppWebViewController controller, RenderProcessGoneDetail detail)?
onRenderProcessGone;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final Future<WebViewRenderProcessAction?> Function(
InAppWebViewController controller, Uri? url)? onRenderProcessResponsive;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final Future<WebViewRenderProcessAction?> Function(
InAppWebViewController controller, Uri? url)? onRenderProcessUnresponsive;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final Future<SafeBrowsingResponse?> Function(
InAppWebViewController controller,
Uri url,
SafeBrowsingThreat? threatType)? onSafeBrowsingHit;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final void Function(InAppWebViewController controller)?
onWebContentProcessDidTerminate;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final Future<ShouldAllowDeprecatedTLSAction?> Function(
InAppWebViewController controller,
URLAuthenticationChallenge challenge)? shouldAllowDeprecatedTLS;
2022-04-19 23:31:14 +00:00
@override
2022-04-20 01:05:46 +00:00
final Future<WebResourceResponse?> Function(
InAppWebViewController controller, WebResourceRequest request)?
shouldInterceptRequest;
}
class _InAppWebViewState extends State<InAppWebView> {
2022-04-29 00:07:01 +00:00
InAppWebViewController? _controller;
@override
Widget build(BuildContext context) {
2022-04-20 01:05:46 +00:00
Map<String, dynamic> initialSettings = widget.initialSettings?.toMap() ??
// ignore: deprecated_member_use_from_same_package
widget.initialOptions?.toMap() ??
{};
Map<String, dynamic> pullToRefreshSettings =
widget.pullToRefreshController?.settings.toMap() ??
// ignore: deprecated_member_use_from_same_package
widget.pullToRefreshController?.options.toMap() ??
PullToRefreshSettings(enabled: false).toMap();
2022-04-19 23:31:14 +00:00
2022-04-21 21:14:51 +00:00
if (kIsWeb) {
return HtmlElementView(
viewType: 'com.pichillilorenzo/flutter_inappwebview',
onPlatformViewCreated: (int viewId) {
var webViewHtmlElement = WebPlatformManager.webViews[viewId]!;
webViewHtmlElement.initialSettings = widget.initialSettings;
webViewHtmlElement.initialUrlRequest = widget.initialUrlRequest;
webViewHtmlElement.initialFile = widget.initialFile;
webViewHtmlElement.initialData = widget.initialData;
webViewHtmlElement.prepare();
webViewHtmlElement.makeInitialLoad();
_onPlatformViewCreated(viewId);
},
);
} else if (defaultTargetPlatform == TargetPlatform.android) {
2022-04-20 01:05:46 +00:00
var useHybridComposition = (widget.initialSettings != null
? widget.initialSettings?.useHybridComposition
:
// ignore: deprecated_member_use_from_same_package
widget.initialOptions?.android.useHybridComposition) ??
2022-04-29 19:48:17 +00:00
true;
if (!useHybridComposition && widget.pullToRefreshController != null) {
2021-03-06 15:13:05 +00:00
throw new Exception(
"To use the pull-to-refresh feature, useHybridComposition Android-specific option MUST be true!");
}
if (useHybridComposition) {
return PlatformViewLink(
viewType: 'com.pichillilorenzo/flutter_inappwebview',
surfaceFactory: (
2021-02-22 22:54:09 +00:00
BuildContext context,
PlatformViewController controller,
) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
2021-02-22 22:54:09 +00:00
gestureRecognizers: widget.gestureRecognizers ??
const <Factory<OneSequenceGestureRecognizer>>{},
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
);
},
onCreatePlatformView: (PlatformViewCreationParams params) {
return PlatformViewsService.initSurfaceAndroidView(
id: params.id,
viewType: 'com.pichillilorenzo/flutter_inappwebview',
layoutDirection: TextDirection.rtl,
creationParams: <String, dynamic>{
'initialUrlRequest': widget.initialUrlRequest?.toMap(),
'initialFile': widget.initialFile,
'initialData': widget.initialData?.toMap(),
2022-04-19 23:31:14 +00:00
'initialSettings': initialSettings,
'contextMenu': widget.contextMenu?.toMap() ?? {},
'windowId': widget.windowId,
'implementation': widget.implementation.toValue(),
2021-02-22 22:54:09 +00:00
'initialUserScripts':
widget.initialUserScripts?.map((e) => e.toMap()).toList() ??
[],
2022-04-20 01:05:46 +00:00
'pullToRefreshSettings': pullToRefreshSettings
},
creationParamsCodec: const StandardMessageCodec(),
)
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
2021-02-22 22:54:09 +00:00
..addOnPlatformViewCreatedListener(
(id) => _onPlatformViewCreated(id))
..create();
},
);
} else {
return AndroidView(
viewType: 'com.pichillilorenzo/flutter_inappwebview',
onPlatformViewCreated: _onPlatformViewCreated,
gestureRecognizers: widget.gestureRecognizers,
layoutDirection: Directionality.maybeOf(context) ?? TextDirection.rtl,
creationParams: <String, dynamic>{
'initialUrlRequest': widget.initialUrlRequest?.toMap(),
'initialFile': widget.initialFile,
'initialData': widget.initialData?.toMap(),
2022-04-19 23:31:14 +00:00
'initialSettings': initialSettings,
'contextMenu': widget.contextMenu?.toMap() ?? {},
'windowId': widget.windowId,
'implementation': widget.implementation.toValue(),
2021-02-22 22:54:09 +00:00
'initialUserScripts':
widget.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
2022-04-20 01:05:46 +00:00
'pullToRefreshSettings': pullToRefreshSettings
},
creationParamsCodec: const StandardMessageCodec(),
);
}
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
return UiKitView(
viewType: 'com.pichillilorenzo/flutter_inappwebview',
onPlatformViewCreated: _onPlatformViewCreated,
gestureRecognizers: widget.gestureRecognizers,
creationParams: <String, dynamic>{
'initialUrlRequest': widget.initialUrlRequest?.toMap(),
'initialFile': widget.initialFile,
'initialData': widget.initialData?.toMap(),
2022-04-19 23:31:14 +00:00
'initialSettings': initialSettings,
'contextMenu': widget.contextMenu?.toMap() ?? {},
'windowId': widget.windowId,
'implementation': widget.implementation.toValue(),
2021-02-22 22:54:09 +00:00
'initialUserScripts':
widget.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
2022-04-20 01:05:46 +00:00
'pullToRefreshSettings': pullToRefreshSettings
},
creationParamsCodec: const StandardMessageCodec(),
);
}
return Text(
2019-11-29 15:59:18 +00:00
'$defaultTargetPlatform is not yet supported by the flutter_inappwebview plugin');
}
@override
void didUpdateWidget(InAppWebView oldWidget) {
super.didUpdateWidget(oldWidget);
}
2019-11-07 23:32:29 +00:00
@override
void dispose() {
2022-04-29 00:07:01 +00:00
dynamic viewId = _controller?.getViewId();
if (viewId != null && kIsWeb && WebPlatformManager.webViews.containsKey(viewId)) {
2022-04-21 21:14:51 +00:00
WebPlatformManager.webViews.remove(viewId);
}
2019-11-07 23:32:29 +00:00
super.dispose();
2022-04-29 00:07:01 +00:00
_controller = null;
2019-11-07 23:32:29 +00:00
}
void _onPlatformViewCreated(int id) {
_controller = InAppWebViewController(id, widget);
widget.pullToRefreshController?.initMethodChannel(id);
if (widget.onWebViewCreated != null) {
2022-04-29 00:07:01 +00:00
widget.onWebViewCreated!(_controller!);
}
}
}