setCustomWidgetCallbacks method

Future<void> setCustomWidgetCallbacks({
  1. required OnShowCustomWidgetCallback? onShowCustomWidget,
  2. required OnHideCustomWidgetCallback? onHideCustomWidget,
})

Sets the callbacks that are invoked when the host application wants to show or hide a custom widget.

The most common use case these methods are invoked a video element wants to be displayed in fullscreen.

The onShowCustomWidget notifies the host application that web content from the specified origin wants to be displayed in a custom widget. After this call, web content will no longer be rendered in the WebViewWidget, but will instead be rendered in the custom widget. The application may explicitly exit fullscreen mode by invoking onCustomWidgetHidden in the onShowCustomWidget callback (ex. when the user presses the back button). However, this is generally not necessary as the web page will often show its own UI to close out of fullscreen. Regardless of how the WebView exits fullscreen mode, WebView will invoke onHideCustomWidget, signaling for the application to remove the custom widget. If this value is null when passed to an AndroidWebViewWidget, a default handler will be set.

The onHideCustomWidget notifies the host application that the custom widget must be hidden. After this call, web content will render in the original WebViewWidget again.

Implementation

Future<void> setCustomWidgetCallbacks({
  required OnShowCustomWidgetCallback? onShowCustomWidget,
  required OnHideCustomWidgetCallback? onHideCustomWidget,
}) async {
  _onShowCustomWidgetCallback = onShowCustomWidget;
  _onHideCustomWidgetCallback = onHideCustomWidget;
}