onFullScreenStateChanged method
Future<void>
onFullScreenStateChanged({
- required dynamic onVideoStateChange(
- VideoState state
Implementation
Future<void> onFullScreenStateChanged({
required Function(VideoState state)? onVideoStateChange,
}) async {
// Inject JavaScript to listen for fullscreen changes
await controller.evaluateJavascript(source: """
document.addEventListener('fullscreenchange', function() {
if (document.fullscreenElement) {
window.flutter_inappwebview.callHandler('onEnterFullscreen');
} else {
window.flutter_inappwebview.callHandler('onExitFullscreen');
}
});
""");
// Register JavaScript handlers for fullscreen events
controller.addJavaScriptHandler(
handlerName: 'onEnterFullscreen',
callback: (args) {
// Notify Flutter when entering fullscreen
if (onVideoStateChange != null) {
onVideoStateChange.call(VideoState.fullscreen);
}
},
);
controller.addJavaScriptHandler(
handlerName: 'onExitFullscreen',
callback: (args) {
// Notify Flutter when exiting fullscreen
if (onVideoStateChange != null) {
onVideoStateChange.call(VideoState.normalView);
}
},
);
}