2019-11-02 03:16:47 +00:00
|
|
|
import 'dart:async';
|
2021-02-01 14:55:27 +00:00
|
|
|
import 'dart:collection';
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
import 'dart:typed_data';
|
2019-11-02 03:16:47 +00:00
|
|
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-07-27 09:52:37 +00:00
|
|
|
import 'package:flutter/rendering.dart';
|
2019-11-02 03:16:47 +00:00
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
|
2020-05-21 01:34:39 +00:00
|
|
|
import 'context_menu.dart';
|
2020-05-11 00:48:41 +00:00
|
|
|
import 'webview.dart';
|
2019-11-02 03:16:47 +00:00
|
|
|
import 'types.dart';
|
2020-05-11 00:48:41 +00:00
|
|
|
import 'in_app_webview_controller.dart';
|
2019-11-02 03:16:47 +00:00
|
|
|
|
|
|
|
///Flutter Widget for adding an **inline native WebView** integrated in the flutter widget tree.
|
2020-05-11 00:48:41 +00:00
|
|
|
class InAppWebView extends StatefulWidget implements WebView {
|
2020-06-12 02:04:41 +00:00
|
|
|
/// `gestureRecognizers` specifies which gestures should be consumed by the WebView.
|
2019-11-02 03:16:47 +00:00
|
|
|
/// 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.
|
2021-01-28 16:10:15 +00:00
|
|
|
final Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers;
|
2019-11-02 03:16:47 +00:00
|
|
|
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
///The window id of a [CreateWindowRequest.windowId].
|
2021-01-28 16:10:15 +00:00
|
|
|
final int? windowId;
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
|
2019-11-02 03:16:47 +00:00
|
|
|
const InAppWebView({
|
2021-01-28 16:10:15 +00:00
|
|
|
Key? key,
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
this.windowId,
|
2019-11-02 03:16:47 +00:00
|
|
|
this.initialUrl = "about:blank",
|
|
|
|
this.initialFile,
|
|
|
|
this.initialData,
|
|
|
|
this.initialHeaders = const {},
|
2020-05-28 23:03:45 +00:00
|
|
|
this.initialOptions,
|
2021-02-01 14:55:27 +00:00
|
|
|
this.initialUserScripts,
|
2020-05-21 01:34:39 +00:00
|
|
|
this.contextMenu,
|
2019-11-02 03:16:47 +00:00
|
|
|
this.onWebViewCreated,
|
|
|
|
this.onLoadStart,
|
|
|
|
this.onLoadStop,
|
|
|
|
this.onLoadError,
|
2019-11-21 01:19:43 +00:00
|
|
|
this.onLoadHttpError,
|
2019-11-02 03:16:47 +00:00
|
|
|
this.onConsoleMessage,
|
|
|
|
this.onProgressChanged,
|
|
|
|
this.shouldOverrideUrlLoading,
|
|
|
|
this.onLoadResource,
|
|
|
|
this.onScrollChanged,
|
|
|
|
this.onDownloadStart,
|
|
|
|
this.onLoadResourceCustomScheme,
|
2019-12-09 23:29:09 +00:00
|
|
|
this.onCreateWindow,
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
this.onCloseWindow,
|
2019-11-02 03:16:47 +00:00
|
|
|
this.onJsAlert,
|
|
|
|
this.onJsConfirm,
|
|
|
|
this.onJsPrompt,
|
|
|
|
this.onReceivedHttpAuthRequest,
|
|
|
|
this.onReceivedServerTrustAuthRequest,
|
|
|
|
this.onReceivedClientCertRequest,
|
|
|
|
this.onFindResultReceived,
|
2019-11-05 02:44:22 +00:00
|
|
|
this.shouldInterceptAjaxRequest,
|
|
|
|
this.onAjaxReadyStateChange,
|
2019-11-05 23:23:24 +00:00
|
|
|
this.onAjaxProgress,
|
2019-11-05 02:44:22 +00:00
|
|
|
this.shouldInterceptFetchRequest,
|
2019-12-16 22:58:10 +00:00
|
|
|
this.onUpdateVisitedHistory,
|
2019-12-09 23:29:09 +00:00
|
|
|
this.onPrint,
|
2020-05-09 02:36:07 +00:00
|
|
|
this.onLongPressHitTestResult,
|
2020-05-23 17:33:54 +00:00
|
|
|
this.onEnterFullscreen,
|
|
|
|
this.onExitFullscreen,
|
2020-05-28 23:03:45 +00:00
|
|
|
this.onPageCommitVisible,
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
this.onTitleChanged,
|
|
|
|
this.onWindowFocus,
|
|
|
|
this.onWindowBlur,
|
2019-12-16 22:58:10 +00:00
|
|
|
this.androidOnSafeBrowsingHit,
|
|
|
|
this.androidOnPermissionRequest,
|
|
|
|
this.androidOnGeolocationPermissionsShowPrompt,
|
|
|
|
this.androidOnGeolocationPermissionsHidePrompt,
|
2020-05-28 23:03:45 +00:00
|
|
|
this.androidShouldInterceptRequest,
|
|
|
|
this.androidOnRenderProcessGone,
|
|
|
|
this.androidOnRenderProcessResponsive,
|
|
|
|
this.androidOnRenderProcessUnresponsive,
|
|
|
|
this.androidOnFormResubmission,
|
|
|
|
this.androidOnScaleChanged,
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
this.androidOnRequestFocus,
|
|
|
|
this.androidOnReceivedIcon,
|
|
|
|
this.androidOnReceivedTouchIconUrl,
|
|
|
|
this.androidOnJsBeforeUnload,
|
|
|
|
this.androidOnReceivedLoginRequest,
|
2020-05-09 02:36:07 +00:00
|
|
|
this.iosOnWebContentProcessDidTerminate,
|
|
|
|
this.iosOnDidReceiveServerRedirectForProvisionalNavigation,
|
2021-02-09 23:15:10 +00:00
|
|
|
this.iosOnNavigationResponse,
|
2019-11-02 03:16:47 +00:00
|
|
|
this.gestureRecognizers,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_InAppWebViewState createState() => _InAppWebViewState();
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller)?
|
2020-05-11 00:48:41 +00:00
|
|
|
androidOnGeolocationPermissionsHidePrompt;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<GeolocationPermissionShowPromptResponse?> Function(
|
|
|
|
InAppWebViewController controller, String origin)?
|
2020-05-11 00:48:41 +00:00
|
|
|
androidOnGeolocationPermissionsShowPrompt;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<PermissionRequestResponse?> Function(
|
2020-05-11 00:48:41 +00:00
|
|
|
InAppWebViewController controller,
|
|
|
|
String origin,
|
2021-01-28 16:10:15 +00:00
|
|
|
List<String> resources)? androidOnPermissionRequest;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<SafeBrowsingResponse?> Function(InAppWebViewController controller,
|
|
|
|
String url, SafeBrowsingThreat? threatType)? androidOnSafeBrowsingHit;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final InAppWebViewInitialData? initialData;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final String? initialFile;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Map<String, String>? initialHeaders;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final InAppWebViewGroupOptions? initialOptions;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final String? initialUrl;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
2021-02-01 14:55:27 +00:00
|
|
|
@override
|
|
|
|
final UnmodifiableListView<UserScript>? initialUserScripts;
|
|
|
|
|
2020-05-21 01:34:39 +00:00
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final ContextMenu? contextMenu;
|
2020-05-21 01:34:39 +00:00
|
|
|
|
2020-05-11 00:48:41 +00:00
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, String? url)?
|
2020-05-29 17:56:03 +00:00
|
|
|
onPageCommitVisible;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, String? title)?
|
2020-06-29 14:37:36 +00:00
|
|
|
onTitleChanged;
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller)?
|
2020-05-11 00:48:41 +00:00
|
|
|
iosOnDidReceiveServerRedirectForProvisionalNavigation;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller)?
|
2020-05-11 00:48:41 +00:00
|
|
|
iosOnWebContentProcessDidTerminate;
|
|
|
|
|
2021-02-09 23:15:10 +00:00
|
|
|
@override
|
|
|
|
final Future<IOSNavigationResponseAction?> Function(InAppWebViewController controller,
|
|
|
|
IOSNavigationResponse navigationResponse)?
|
|
|
|
iosOnNavigationResponse;
|
|
|
|
|
2020-05-11 00:48:41 +00:00
|
|
|
@override
|
|
|
|
final Future<AjaxRequestAction> Function(
|
2021-01-28 16:10:15 +00:00
|
|
|
InAppWebViewController controller, AjaxRequest ajaxRequest)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onAjaxProgress;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<AjaxRequestAction?> Function(
|
|
|
|
InAppWebViewController controller, AjaxRequest ajaxRequest)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onAjaxReadyStateChange;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final void Function(
|
2021-01-28 16:10:15 +00:00
|
|
|
InAppWebViewController controller, ConsoleMessage consoleMessage)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onConsoleMessage;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<bool?> Function(InAppWebViewController controller,
|
|
|
|
CreateWindowRequest createWindowRequest)? onCreateWindow;
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller)? onCloseWindow;
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller)? onWindowFocus;
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller)? onWindowBlur;
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller)? androidOnRequestFocus;
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, Uint8List icon)?
|
2020-06-29 14:37:36 +00:00
|
|
|
androidOnReceivedIcon;
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
|
|
|
|
@override
|
2020-06-29 14:37:36 +00:00
|
|
|
final void Function(
|
2021-01-28 16:10:15 +00:00
|
|
|
InAppWebViewController controller, String url, bool precomposed)?
|
2020-06-29 14:37:36 +00:00
|
|
|
androidOnReceivedTouchIconUrl;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, String url)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onDownloadStart;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final void Function(InAppWebViewController controller, int activeMatchOrdinal,
|
2021-01-28 16:10:15 +00:00
|
|
|
int numberOfMatches, bool isDoneCounting)? onFindResultReceived;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<JsAlertResponse?> Function(
|
|
|
|
InAppWebViewController controller, JsAlertRequest jsAlertRequest)?
|
2020-06-29 14:37:36 +00:00
|
|
|
onJsAlert;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<JsConfirmResponse?> Function(
|
|
|
|
InAppWebViewController controller, JsConfirmRequest jsConfirmRequest)?
|
2020-06-29 14:37:36 +00:00
|
|
|
onJsConfirm;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<JsPromptResponse?> Function(
|
|
|
|
InAppWebViewController controller, JsPromptRequest jsPromptRequest)?
|
2020-06-29 14:37:36 +00:00
|
|
|
onJsPrompt;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, String? url, int code,
|
|
|
|
String message)? onLoadError;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, String? url,
|
|
|
|
int statusCode, String description)? onLoadHttpError;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
final void Function(
|
2021-01-28 16:10:15 +00:00
|
|
|
InAppWebViewController controller, LoadedResource resource)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onLoadResource;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<CustomSchemeResponse?> Function(
|
|
|
|
InAppWebViewController controller, String scheme, String url)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onLoadResourceCustomScheme;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, String? url)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onLoadStart;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, String? url)? onLoadStop;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
final void Function(InAppWebViewController controller,
|
2021-01-28 16:10:15 +00:00
|
|
|
InAppWebViewHitTestResult hitTestResult)? onLongPressHitTestResult;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, String? url)? onPrint;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, int progress)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onProgressChanged;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<ClientCertResponse?> Function(
|
|
|
|
InAppWebViewController controller, ClientCertChallenge challenge)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onReceivedClientCertRequest;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<HttpAuthResponse?> Function(
|
|
|
|
InAppWebViewController controller, HttpAuthChallenge challenge)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onReceivedHttpAuthRequest;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<ServerTrustAuthResponse?> Function(
|
|
|
|
InAppWebViewController controller, ServerTrustChallenge challenge)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onReceivedServerTrustAuthRequest;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller, int x, int y)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onScrollChanged;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final void Function(
|
2021-01-28 16:10:15 +00:00
|
|
|
InAppWebViewController controller, String? url, bool? androidIsReload)?
|
2020-05-11 00:48:41 +00:00
|
|
|
onUpdateVisitedHistory;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller)? onWebViewCreated;
|
2020-05-11 00:48:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<AjaxRequest?> Function(
|
|
|
|
InAppWebViewController controller, AjaxRequest ajaxRequest)?
|
2020-05-11 00:48:41 +00:00
|
|
|
shouldInterceptAjaxRequest;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<FetchRequest?> Function(
|
|
|
|
InAppWebViewController controller, FetchRequest fetchRequest)?
|
2020-05-11 00:48:41 +00:00
|
|
|
shouldInterceptFetchRequest;
|
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<ShouldOverrideUrlLoadingAction?> Function(
|
2020-05-11 00:48:41 +00:00
|
|
|
InAppWebViewController controller,
|
2021-01-28 16:10:15 +00:00
|
|
|
ShouldOverrideUrlLoadingRequest shouldOverrideUrlLoadingRequest)?
|
2020-05-11 00:48:41 +00:00
|
|
|
shouldOverrideUrlLoading;
|
2020-05-23 17:33:54 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller)? onEnterFullscreen;
|
2020-05-23 17:33:54 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final void Function(InAppWebViewController controller)? onExitFullscreen;
|
2020-05-28 23:03:45 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<WebResourceResponse?> Function(
|
|
|
|
InAppWebViewController controller, WebResourceRequest request)?
|
2020-05-29 17:56:03 +00:00
|
|
|
androidShouldInterceptRequest;
|
2020-05-28 23:03:45 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<WebViewRenderProcessAction?> Function(
|
|
|
|
InAppWebViewController controller, String? url)?
|
2020-05-29 17:56:03 +00:00
|
|
|
androidOnRenderProcessUnresponsive;
|
2020-05-28 23:03:45 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<WebViewRenderProcessAction?> Function(
|
|
|
|
InAppWebViewController controller, String? url)?
|
2020-05-29 17:56:03 +00:00
|
|
|
androidOnRenderProcessResponsive;
|
2020-05-28 23:03:45 +00:00
|
|
|
|
|
|
|
@override
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
final void Function(
|
2021-01-28 16:10:15 +00:00
|
|
|
InAppWebViewController controller, RenderProcessGoneDetail detail)?
|
2020-05-29 17:56:03 +00:00
|
|
|
androidOnRenderProcessGone;
|
2020-05-28 23:03:45 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<FormResubmissionAction?> Function(
|
|
|
|
InAppWebViewController controller, String? url)? androidOnFormResubmission;
|
2020-05-28 23:03:45 +00:00
|
|
|
|
|
|
|
@override
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
final void Function(
|
2021-01-28 16:10:15 +00:00
|
|
|
InAppWebViewController controller, double oldScale, double newScale)?
|
2020-05-29 17:56:03 +00:00
|
|
|
androidOnScaleChanged;
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-28 16:10:15 +00:00
|
|
|
final Future<JsBeforeUnloadResponse?> Function(
|
2020-06-29 14:37:36 +00:00
|
|
|
InAppWebViewController controller,
|
2021-01-28 16:10:15 +00:00
|
|
|
JsBeforeUnloadRequest jsBeforeUnloadRequest)? androidOnJsBeforeUnload;
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
|
|
|
|
@override
|
2020-06-29 14:37:36 +00:00
|
|
|
final void Function(
|
2021-01-28 16:10:15 +00:00
|
|
|
InAppWebViewController controller, LoginRequest loginRequest)?
|
2020-06-29 14:37:36 +00:00
|
|
|
androidOnReceivedLoginRequest;
|
2019-11-02 03:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _InAppWebViewState extends State<InAppWebView> {
|
2021-01-28 16:10:15 +00:00
|
|
|
late InAppWebViewController _controller;
|
2019-11-02 03:16:47 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (defaultTargetPlatform == TargetPlatform.android) {
|
2020-08-27 14:41:40 +00:00
|
|
|
if (widget.initialOptions?.android?.useHybridComposition ?? false) {
|
2020-08-24 15:48:50 +00:00
|
|
|
return PlatformViewLink(
|
|
|
|
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
|
|
|
surfaceFactory: (
|
|
|
|
BuildContext context,
|
|
|
|
PlatformViewController controller,
|
|
|
|
) {
|
|
|
|
return AndroidViewSurface(
|
2021-01-28 16:10:15 +00:00
|
|
|
controller: controller as AndroidViewController,
|
2020-08-24 15:48:50 +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>{
|
2021-01-28 16:10:15 +00:00
|
|
|
'initialUrl': widget.initialUrl != null ? '${Uri.parse(widget.initialUrl!)}' : '',
|
2020-08-24 15:48:50 +00:00
|
|
|
'initialFile': widget.initialFile,
|
|
|
|
'initialData': widget.initialData?.toMap(),
|
|
|
|
'initialHeaders': widget.initialHeaders,
|
2020-08-27 13:42:13 +00:00
|
|
|
'initialOptions': widget.initialOptions?.toMap() ?? {},
|
|
|
|
'contextMenu': widget.contextMenu?.toMap() ?? {},
|
2021-02-01 14:55:27 +00:00
|
|
|
'windowId': widget.windowId,
|
|
|
|
'initialUserScripts': widget.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
|
2020-08-24 15:48:50 +00:00
|
|
|
},
|
|
|
|
creationParamsCodec: const StandardMessageCodec(),
|
|
|
|
)
|
|
|
|
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
|
|
|
|
..addOnPlatformViewCreatedListener((id) => _onPlatformViewCreated(id))
|
|
|
|
..create();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return AndroidView(
|
|
|
|
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
|
|
|
onPlatformViewCreated: _onPlatformViewCreated,
|
|
|
|
gestureRecognizers: widget.gestureRecognizers,
|
|
|
|
layoutDirection: TextDirection.rtl,
|
|
|
|
creationParams: <String, dynamic>{
|
2021-01-28 16:10:15 +00:00
|
|
|
'initialUrl': widget.initialUrl != null ? '${Uri.parse(widget.initialUrl!)}' : '',
|
2020-08-24 15:48:50 +00:00
|
|
|
'initialFile': widget.initialFile,
|
|
|
|
'initialData': widget.initialData?.toMap(),
|
|
|
|
'initialHeaders': widget.initialHeaders,
|
|
|
|
'initialOptions': widget.initialOptions?.toMap() ?? {},
|
|
|
|
'contextMenu': widget.contextMenu?.toMap() ?? {},
|
2021-02-01 14:55:27 +00:00
|
|
|
'windowId': widget.windowId,
|
|
|
|
'initialUserScripts': widget.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
|
2020-08-24 15:48:50 +00:00
|
|
|
},
|
|
|
|
creationParamsCodec: const StandardMessageCodec(),
|
|
|
|
);
|
|
|
|
}
|
2019-11-02 03:16:47 +00:00
|
|
|
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
|
|
|
|
return UiKitView(
|
|
|
|
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
|
|
|
onPlatformViewCreated: _onPlatformViewCreated,
|
|
|
|
gestureRecognizers: widget.gestureRecognizers,
|
|
|
|
creationParams: <String, dynamic>{
|
2021-01-28 16:10:15 +00:00
|
|
|
'initialUrl': widget.initialUrl != null ? '${Uri.parse(widget.initialUrl!)}' : '',
|
2019-11-02 03:16:47 +00:00
|
|
|
'initialFile': widget.initialFile,
|
|
|
|
'initialData': widget.initialData?.toMap(),
|
|
|
|
'initialHeaders': widget.initialHeaders,
|
2020-05-21 01:34:39 +00:00
|
|
|
'initialOptions': widget.initialOptions?.toMap() ?? {},
|
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
|
|
|
'contextMenu': widget.contextMenu?.toMap() ?? {},
|
2021-02-01 14:55:27 +00:00
|
|
|
'windowId': widget.windowId,
|
|
|
|
'initialUserScripts': widget.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
|
2019-11-02 03:16:47 +00:00
|
|
|
},
|
|
|
|
creationParamsCodec: const StandardMessageCodec(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Text(
|
2019-11-29 15:59:18 +00:00
|
|
|
'$defaultTargetPlatform is not yet supported by the flutter_inappwebview plugin');
|
2019-11-02 03:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didUpdateWidget(InAppWebView oldWidget) {
|
|
|
|
super.didUpdateWidget(oldWidget);
|
|
|
|
}
|
|
|
|
|
2019-11-07 23:32:29 +00:00
|
|
|
@override
|
2019-12-01 11:55:06 +00:00
|
|
|
void dispose() {
|
2019-11-07 23:32:29 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2019-11-02 03:16:47 +00:00
|
|
|
void _onPlatformViewCreated(int id) {
|
|
|
|
_controller = InAppWebViewController(id, widget);
|
|
|
|
if (widget.onWebViewCreated != null) {
|
2021-01-28 16:10:15 +00:00
|
|
|
widget.onWebViewCreated!(_controller);
|
2019-11-02 03:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|