HeadlessInAppWebView constructor

HeadlessInAppWebView({
  1. Size initialSize = const Size(-1, -1),
  2. int? windowId,
  3. URLRequest? initialUrlRequest,
  4. String? initialFile,
  5. InAppWebViewInitialData? initialData,
  6. @Deprecated('Use initialSettings instead') InAppWebViewGroupOptions? initialOptions,
  7. InAppWebViewSettings? initialSettings,
  8. ContextMenu? contextMenu,
  9. UnmodifiableListView<UserScript>? initialUserScripts,
  10. PullToRefreshController? pullToRefreshController,
  11. FindInteractionController? findInteractionController,
  12. WebViewImplementation implementation = WebViewImplementation.NATIVE,
  13. void onWebViewCreated(
    1. InAppWebViewController controller
    )?,
  14. void onLoadStart(
    1. InAppWebViewController controller,
    2. WebUri? url
    )?,
  15. void onLoadStop(
    1. InAppWebViewController controller,
    2. WebUri? url
    )?,
  16. @Deprecated("Use onReceivedError instead") void onLoadError(
    1. InAppWebViewController controller,
    2. Uri? url,
    3. int code,
    4. String message,
    )?,
  17. void onReceivedError(
    1. InAppWebViewController controller,
    2. WebResourceRequest request,
    3. WebResourceError error
    )?,
  18. @Deprecated("Use onReceivedHttpError instead") void onLoadHttpError(
    1. InAppWebViewController controller,
    2. Uri? url,
    3. int statusCode,
    4. String description,
    )?,
  19. void onReceivedHttpError(
    1. InAppWebViewController controller,
    2. WebResourceRequest request,
    3. WebResourceResponse errorResponse
    )?,
  20. void onProgressChanged(
    1. InAppWebViewController controller,
    2. int progress
    )?,
  21. void onConsoleMessage(
    1. InAppWebViewController controller,
    2. ConsoleMessage consoleMessage
    )?,
  22. Future<NavigationActionPolicy?> shouldOverrideUrlLoading(
    1. InAppWebViewController controller,
    2. NavigationAction navigationAction
    )?,
  23. void onLoadResource(
    1. InAppWebViewController controller,
    2. LoadedResource resource
    )?,
  24. void onScrollChanged(
    1. InAppWebViewController controller,
    2. int x,
    3. int y
    )?,
  25. @Deprecated('Use onDownloadStartRequest instead') void onDownloadStart(
    1. InAppWebViewController controller,
    2. Uri url
    )?,
  26. void onDownloadStartRequest(
    1. InAppWebViewController controller,
    2. DownloadStartRequest downloadStartRequest
    )?,
  27. @Deprecated('Use onLoadResourceWithCustomScheme instead') Future<CustomSchemeResponse?> onLoadResourceCustomScheme(
    1. InAppWebViewController controller,
    2. Uri url
    )?,
  28. Future<CustomSchemeResponse?> onLoadResourceWithCustomScheme(
    1. InAppWebViewController controller,
    2. WebResourceRequest request
    )?,
  29. Future<bool?> onCreateWindow(
    1. InAppWebViewController controller,
    2. CreateWindowAction createWindowAction
    )?,
  30. void onCloseWindow(
    1. InAppWebViewController controller
    )?,
  31. Future<JsAlertResponse?> onJsAlert(
    1. InAppWebViewController controller,
    2. JsAlertRequest jsAlertRequest
    )?,
  32. Future<JsConfirmResponse?> onJsConfirm(
    1. InAppWebViewController controller,
    2. JsConfirmRequest jsConfirmRequest
    )?,
  33. Future<JsPromptResponse?> onJsPrompt(
    1. InAppWebViewController controller,
    2. JsPromptRequest jsPromptRequest
    )?,
  34. Future<HttpAuthResponse?> onReceivedHttpAuthRequest(
    1. InAppWebViewController controller,
    2. URLAuthenticationChallenge challenge
    )?,
  35. Future<ServerTrustAuthResponse?> onReceivedServerTrustAuthRequest(
    1. InAppWebViewController controller,
    2. URLAuthenticationChallenge challenge
    )?,
  36. Future<ClientCertResponse?> onReceivedClientCertRequest(
    1. InAppWebViewController controller,
    2. URLAuthenticationChallenge challenge
    )?,
  37. @Deprecated('Use FindInteractionController.onFindResultReceived instead') void onFindResultReceived(
    1. InAppWebViewController controller,
    2. int activeMatchOrdinal,
    3. int numberOfMatches,
    4. bool isDoneCounting,
    )?,
  38. Future<AjaxRequest?> shouldInterceptAjaxRequest(
    1. InAppWebViewController controller,
    2. AjaxRequest ajaxRequest
    )?,
  39. Future<AjaxRequestAction?> onAjaxReadyStateChange(
    1. InAppWebViewController controller,
    2. AjaxRequest ajaxRequest
    )?,
  40. Future<AjaxRequestAction> onAjaxProgress(
    1. InAppWebViewController controller,
    2. AjaxRequest ajaxRequest
    )?,
  41. Future<FetchRequest?> shouldInterceptFetchRequest(
    1. InAppWebViewController controller,
    2. FetchRequest fetchRequest
    )?,
  42. void onUpdateVisitedHistory(
    1. InAppWebViewController controller,
    2. WebUri? url,
    3. bool? isReload
    )?,
  43. @Deprecated("Use onPrintRequest instead") void onPrint(
    1. InAppWebViewController controller,
    2. Uri? url
    )?,
  44. Future<bool?> onPrintRequest(
    1. InAppWebViewController controller,
    2. WebUri? url,
    3. PrintJobController? printJobController
    )?,
  45. void onLongPressHitTestResult(
    1. InAppWebViewController controller,
    2. InAppWebViewHitTestResult hitTestResult
    )?,
  46. void onEnterFullscreen(
    1. InAppWebViewController controller
    )?,
  47. void onExitFullscreen(
    1. InAppWebViewController controller
    )?,
  48. void onPageCommitVisible(
    1. InAppWebViewController controller,
    2. WebUri? url
    )?,
  49. void onTitleChanged(
    1. InAppWebViewController controller,
    2. String? title
    )?,
  50. void onWindowFocus(
    1. InAppWebViewController controller
    )?,
  51. void onWindowBlur(
    1. InAppWebViewController controller
    )?,
  52. void onOverScrolled(
    1. InAppWebViewController controller,
    2. int x,
    3. int y,
    4. bool clampedX,
    5. bool clampedY,
    )?,
  53. @Deprecated('Use onSafeBrowsingHit instead') Future<SafeBrowsingResponse?> androidOnSafeBrowsingHit(
    1. InAppWebViewController controller,
    2. Uri url,
    3. SafeBrowsingThreat? threatType
    )?,
  54. Future<SafeBrowsingResponse?> onSafeBrowsingHit(
    1. InAppWebViewController controller,
    2. WebUri url,
    3. SafeBrowsingThreat? threatType
    )?,
  55. @Deprecated('Use onPermissionRequest instead') Future<PermissionRequestResponse?> androidOnPermissionRequest(
    1. InAppWebViewController controller,
    2. String origin,
    3. List<String> resources
    )?,
  56. Future<PermissionResponse?> onPermissionRequest(
    1. InAppWebViewController controller,
    2. PermissionRequest permissionRequest
    )?,
  57. @Deprecated('Use onGeolocationPermissionsShowPrompt instead') Future<GeolocationPermissionShowPromptResponse?> androidOnGeolocationPermissionsShowPrompt(
    1. InAppWebViewController controller,
    2. String origin
    )?,
  58. Future<GeolocationPermissionShowPromptResponse?> onGeolocationPermissionsShowPrompt(
    1. InAppWebViewController controller,
    2. String origin
    )?,
  59. @Deprecated('Use onGeolocationPermissionsHidePrompt instead') void androidOnGeolocationPermissionsHidePrompt(
    1. InAppWebViewController controller
    )?,
  60. void onGeolocationPermissionsHidePrompt(
    1. InAppWebViewController controller
    )?,
  61. @Deprecated('Use shouldInterceptRequest instead') Future<WebResourceResponse?> androidShouldInterceptRequest(
    1. InAppWebViewController controller,
    2. WebResourceRequest request
    )?,
  62. Future<WebResourceResponse?> shouldInterceptRequest(
    1. InAppWebViewController controller,
    2. WebResourceRequest request
    )?,
  63. @Deprecated('Use onRenderProcessGone instead') void androidOnRenderProcessGone(
    1. InAppWebViewController controller,
    2. RenderProcessGoneDetail detail
    )?,
  64. void onRenderProcessGone(
    1. InAppWebViewController controller,
    2. RenderProcessGoneDetail detail
    )?,
  65. @Deprecated('Use onRenderProcessResponsive instead') Future<WebViewRenderProcessAction?> androidOnRenderProcessResponsive(
    1. InAppWebViewController controller,
    2. Uri? url
    )?,
  66. Future<WebViewRenderProcessAction?> onRenderProcessResponsive(
    1. InAppWebViewController controller,
    2. WebUri? url
    )?,
  67. @Deprecated('Use onRenderProcessUnresponsive instead') Future<WebViewRenderProcessAction?> androidOnRenderProcessUnresponsive(
    1. InAppWebViewController controller,
    2. Uri? url
    )?,
  68. Future<WebViewRenderProcessAction?> onRenderProcessUnresponsive(
    1. InAppWebViewController controller,
    2. WebUri? url
    )?,
  69. @Deprecated('Use onFormResubmission instead') Future<FormResubmissionAction?> androidOnFormResubmission(
    1. InAppWebViewController controller,
    2. Uri? url
    )?,
  70. Future<FormResubmissionAction?> onFormResubmission(
    1. InAppWebViewController controller,
    2. WebUri? url
    )?,
  71. @Deprecated('Use onZoomScaleChanged instead') void androidOnScaleChanged(
    1. InAppWebViewController controller,
    2. double oldScale,
    3. double newScale
    )?,
  72. @Deprecated('Use onReceivedIcon instead') void androidOnReceivedIcon(
    1. InAppWebViewController controller,
    2. Uint8List icon
    )?,
  73. void onReceivedIcon(
    1. InAppWebViewController controller,
    2. Uint8List icon
    )?,
  74. @Deprecated('Use onReceivedTouchIconUrl instead') void androidOnReceivedTouchIconUrl(
    1. InAppWebViewController controller,
    2. Uri url,
    3. bool precomposed
    )?,
  75. void onReceivedTouchIconUrl(
    1. InAppWebViewController controller,
    2. WebUri url,
    3. bool precomposed
    )?,
  76. @Deprecated('Use onJsBeforeUnload instead') Future<JsBeforeUnloadResponse?> androidOnJsBeforeUnload(
    1. InAppWebViewController controller,
    2. JsBeforeUnloadRequest jsBeforeUnloadRequest
    )?,
  77. Future<JsBeforeUnloadResponse?> onJsBeforeUnload(
    1. InAppWebViewController controller,
    2. JsBeforeUnloadRequest jsBeforeUnloadRequest
    )?,
  78. @Deprecated('Use onReceivedLoginRequest instead') void androidOnReceivedLoginRequest(
    1. InAppWebViewController controller,
    2. LoginRequest loginRequest
    )?,
  79. void onReceivedLoginRequest(
    1. InAppWebViewController controller,
    2. LoginRequest loginRequest
    )?,
  80. void onPermissionRequestCanceled(
    1. InAppWebViewController controller,
    2. PermissionRequest permissionRequest
    )?,
  81. void onRequestFocus(
    1. InAppWebViewController controller
    )?,
  82. @Deprecated('Use onWebContentProcessDidTerminate instead') void iosOnWebContentProcessDidTerminate(
    1. InAppWebViewController controller
    )?,
  83. void onWebContentProcessDidTerminate(
    1. InAppWebViewController controller
    )?,
  84. @Deprecated('Use onDidReceiveServerRedirectForProvisionalNavigation instead') void iosOnDidReceiveServerRedirectForProvisionalNavigation(
    1. InAppWebViewController controller
    )?,
  85. void onDidReceiveServerRedirectForProvisionalNavigation(
    1. InAppWebViewController controller
    )?,
  86. @Deprecated('Use onNavigationResponse instead') Future<IOSNavigationResponseAction?> iosOnNavigationResponse(
    1. InAppWebViewController controller,
    2. IOSWKNavigationResponse navigationResponse
    )?,
  87. Future<NavigationResponseAction?> onNavigationResponse(
    1. InAppWebViewController controller,
    2. NavigationResponse navigationResponse
    )?,
  88. @Deprecated('Use shouldAllowDeprecatedTLS instead') Future<IOSShouldAllowDeprecatedTLSAction?> iosShouldAllowDeprecatedTLS(
    1. InAppWebViewController controller,
    2. URLAuthenticationChallenge challenge
    )?,
  89. Future<ShouldAllowDeprecatedTLSAction?> shouldAllowDeprecatedTLS(
    1. InAppWebViewController controller,
    2. URLAuthenticationChallenge challenge
    )?,
  90. Future<void> onCameraCaptureStateChanged(
    1. InAppWebViewController controller,
    2. MediaCaptureState? oldState,
    3. MediaCaptureState? newState
    )?,
  91. Future<void> onMicrophoneCaptureStateChanged(
    1. InAppWebViewController controller,
    2. MediaCaptureState? oldState,
    3. MediaCaptureState? newState
    )?,
  92. void onContentSizeChanged(
    1. InAppWebViewController controller,
    2. Size oldContentSize,
    3. Size newContentSize
    )?,
})

Class that represents a WebView in headless mode. It can be used to run a WebView in background without attaching an InAppWebView to the widget tree.

NOTE: Remember to dispose it when you don't need it anymore.

Supported Platforms/Implementations:

  • Android native WebView
  • iOS
  • Web
  • MacOS

Implementation

HeadlessInAppWebView(
    {this.initialSize = const Size(-1, -1),
    this.windowId,
    this.initialUrlRequest,
    this.initialFile,
    this.initialData,
    @Deprecated('Use initialSettings instead')
        this.initialOptions,
    this.initialSettings,
    this.contextMenu,
    this.initialUserScripts,
    this.pullToRefreshController,
    this.findInteractionController,
    this.implementation = WebViewImplementation.NATIVE,
    this.onWebViewCreated,
    this.onLoadStart,
    this.onLoadStop,
    @Deprecated("Use onReceivedError instead")
        this.onLoadError,
    this.onReceivedError,
    @Deprecated("Use onReceivedHttpError instead")
        this.onLoadHttpError,
    this.onReceivedHttpError,
    this.onProgressChanged,
    this.onConsoleMessage,
    this.shouldOverrideUrlLoading,
    this.onLoadResource,
    this.onScrollChanged,
    @Deprecated('Use onDownloadStartRequest instead')
        this.onDownloadStart,
    this.onDownloadStartRequest,
    @Deprecated('Use onLoadResourceWithCustomScheme instead')
        this.onLoadResourceCustomScheme,
    this.onLoadResourceWithCustomScheme,
    this.onCreateWindow,
    this.onCloseWindow,
    this.onJsAlert,
    this.onJsConfirm,
    this.onJsPrompt,
    this.onReceivedHttpAuthRequest,
    this.onReceivedServerTrustAuthRequest,
    this.onReceivedClientCertRequest,
    @Deprecated('Use FindInteractionController.onFindResultReceived instead')
        this.onFindResultReceived,
    this.shouldInterceptAjaxRequest,
    this.onAjaxReadyStateChange,
    this.onAjaxProgress,
    this.shouldInterceptFetchRequest,
    this.onUpdateVisitedHistory,
    @Deprecated("Use onPrintRequest instead")
        this.onPrint,
    this.onPrintRequest,
    this.onLongPressHitTestResult,
    this.onEnterFullscreen,
    this.onExitFullscreen,
    this.onPageCommitVisible,
    this.onTitleChanged,
    this.onWindowFocus,
    this.onWindowBlur,
    this.onOverScrolled,
    @Deprecated('Use onSafeBrowsingHit instead')
        this.androidOnSafeBrowsingHit,
    this.onSafeBrowsingHit,
    @Deprecated('Use onPermissionRequest instead')
        this.androidOnPermissionRequest,
    this.onPermissionRequest,
    @Deprecated('Use onGeolocationPermissionsShowPrompt instead')
        this.androidOnGeolocationPermissionsShowPrompt,
    this.onGeolocationPermissionsShowPrompt,
    @Deprecated('Use onGeolocationPermissionsHidePrompt instead')
        this.androidOnGeolocationPermissionsHidePrompt,
    this.onGeolocationPermissionsHidePrompt,
    @Deprecated('Use shouldInterceptRequest instead')
        this.androidShouldInterceptRequest,
    this.shouldInterceptRequest,
    @Deprecated('Use onRenderProcessGone instead')
        this.androidOnRenderProcessGone,
    this.onRenderProcessGone,
    @Deprecated('Use onRenderProcessResponsive instead')
        this.androidOnRenderProcessResponsive,
    this.onRenderProcessResponsive,
    @Deprecated('Use onRenderProcessUnresponsive instead')
        this.androidOnRenderProcessUnresponsive,
    this.onRenderProcessUnresponsive,
    @Deprecated('Use onFormResubmission instead')
        this.androidOnFormResubmission,
    this.onFormResubmission,
    @Deprecated('Use onZoomScaleChanged instead')
        this.androidOnScaleChanged,
    @Deprecated('Use onReceivedIcon instead')
        this.androidOnReceivedIcon,
    this.onReceivedIcon,
    @Deprecated('Use onReceivedTouchIconUrl instead')
        this.androidOnReceivedTouchIconUrl,
    this.onReceivedTouchIconUrl,
    @Deprecated('Use onJsBeforeUnload instead')
        this.androidOnJsBeforeUnload,
    this.onJsBeforeUnload,
    @Deprecated('Use onReceivedLoginRequest instead')
        this.androidOnReceivedLoginRequest,
    this.onReceivedLoginRequest,
    this.onPermissionRequestCanceled,
    this.onRequestFocus,
    @Deprecated('Use onWebContentProcessDidTerminate instead')
        this.iosOnWebContentProcessDidTerminate,
    this.onWebContentProcessDidTerminate,
    @Deprecated('Use onDidReceiveServerRedirectForProvisionalNavigation instead')
        this.iosOnDidReceiveServerRedirectForProvisionalNavigation,
    this.onDidReceiveServerRedirectForProvisionalNavigation,
    @Deprecated('Use onNavigationResponse instead')
        this.iosOnNavigationResponse,
    this.onNavigationResponse,
    @Deprecated('Use shouldAllowDeprecatedTLS instead')
        this.iosShouldAllowDeprecatedTLS,
    this.shouldAllowDeprecatedTLS,
    this.onCameraCaptureStateChanged,
    this.onMicrophoneCaptureStateChanged,
    this.onContentSizeChanged}) {
  id = IdGenerator.generate();
  webViewController = new InAppWebViewController(id, this);
  this._channel =
      MethodChannel('com.pichillilorenzo/flutter_headless_inappwebview_$id');
  this._channel.setMethodCallHandler((call) async {
    try {
      return await handleMethod(call);
    } on Error catch (e) {
      print(e);
      print(e.stackTrace);
    }
  });
}