From 4a042bdc8f2f6d5bde4c4debab44291d13d36a77 Mon Sep 17 00:00:00 2001 From: Stephan Veenstra Date: Fri, 12 Jul 2024 14:32:28 +0200 Subject: [PATCH 1/2] Add option to pass OverlayState for showing the fullscreen player --- lib/src/flick_video_player.dart | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/src/flick_video_player.dart b/lib/src/flick_video_player.dart index 94385c5..6d8c3e5 100644 --- a/lib/src/flick_video_player.dart +++ b/lib/src/flick_video_player.dart @@ -1,9 +1,9 @@ -import 'package:flick_video_player/src/utils/web_key_bindings.dart'; -import 'package:universal_html/html.dart'; import 'package:flick_video_player/flick_video_player.dart'; +import 'package:flick_video_player/src/utils/web_key_bindings.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:universal_html/html.dart'; import 'package:wakelock_plus/wakelock_plus.dart'; class FlickVideoPlayer extends StatefulWidget { @@ -27,6 +27,7 @@ class FlickVideoPlayer extends StatefulWidget { this.wakelockEnabled = true, this.wakelockEnabledFullscreen = true, this.webKeyDownHandler = flickDefaultWebKeyDownHandler, + this.overlay, }) : super(key: key); final FlickManager flickManager; @@ -64,12 +65,16 @@ class FlickVideoPlayer extends StatefulWidget { /// Callback called on keyDown for web, used for keyboard shortcuts. final Function(KeyboardEvent, FlickManager) webKeyDownHandler; + /// The [OverlayState] that is used to show the fullscreen player on. + /// + /// Defaults to the overlay from `Overlay.of(context)`. + final OverlayState? overlay; + @override _FlickVideoPlayerState createState() => _FlickVideoPlayerState(); } -class _FlickVideoPlayerState extends State - with WidgetsBindingObserver { +class _FlickVideoPlayerState extends State with WidgetsBindingObserver { late FlickManager flickManager; bool _isFullscreen = false; OverlayEntry? _overlayEntry; @@ -90,8 +95,7 @@ class _FlickVideoPlayerState extends State } if (kIsWeb) { - document.documentElement?.onFullscreenChange - .listen(_webFullscreenListener); + document.documentElement?.onFullscreenChange.listen(_webFullscreenListener); document.documentElement?.onKeyDown.listen(_webKeyListener); } @@ -122,8 +126,7 @@ class _FlickVideoPlayerState extends State void listener() async { if (flickManager.flickControlManager!.isFullscreen && !_isFullscreen) { _switchToFullscreen(); - } else if (_isFullscreen && - !flickManager.flickControlManager!.isFullscreen) { + } else if (_isFullscreen && !flickManager.flickControlManager!.isFullscreen) { _exitFullscreen(); } } @@ -150,13 +153,15 @@ class _FlickVideoPlayerState extends State return Scaffold( body: FlickManagerBuilder( flickManager: flickManager, - child: widget.flickVideoWithControlsFullscreen ?? - widget.flickVideoWithControls, + child: widget.flickVideoWithControlsFullscreen ?? widget.flickVideoWithControls, ), ); }); - Overlay.of(context).insert(_overlayEntry!); + if (widget.overlay != null) + widget.overlay!.insert(_overlayEntry!); + else + Overlay.of(context).insert(_overlayEntry!); } } @@ -184,11 +189,9 @@ class _FlickVideoPlayerState extends State _setPreferredOrientation() { // when aspect ratio is less than 1 , video will be played in portrait mode and orientation will not be changed. - var aspectRatio = - widget.flickManager.flickVideoManager!.videoPlayerValue!.aspectRatio; + var aspectRatio = widget.flickManager.flickVideoManager!.videoPlayerValue!.aspectRatio; if (_isFullscreen && aspectRatio >= 1) { - SystemChrome.setPreferredOrientations( - widget.preferredDeviceOrientationFullscreen); + SystemChrome.setPreferredOrientations(widget.preferredDeviceOrientationFullscreen); } else { SystemChrome.setPreferredOrientations(widget.preferredDeviceOrientation); } @@ -196,11 +199,9 @@ class _FlickVideoPlayerState extends State _setSystemUIOverlays() { if (_isFullscreen) { - SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, - overlays: widget.systemUIOverlayFullscreen); + SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: widget.systemUIOverlayFullscreen); } else { - SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, - overlays: widget.systemUIOverlay); + SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: widget.systemUIOverlay); } } @@ -208,8 +209,7 @@ class _FlickVideoPlayerState extends State final isFullscreen = (window.screenTop == 0 && window.screenY == 0); if (isFullscreen && !flickManager.flickControlManager!.isFullscreen) { flickManager.flickControlManager!.enterFullscreen(); - } else if (!isFullscreen && - flickManager.flickControlManager!.isFullscreen) { + } else if (!isFullscreen && flickManager.flickControlManager!.isFullscreen) { flickManager.flickControlManager!.exitFullscreen(); } } From 5769374c95f504ea251e456e7b83e9071ad925fe Mon Sep 17 00:00:00 2001 From: Stephan Veenstra Date: Fri, 12 Jul 2024 14:53:51 +0200 Subject: [PATCH 2/2] Format code to line length 80 --- lib/src/flick_video_player.dart | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/src/flick_video_player.dart b/lib/src/flick_video_player.dart index 6d8c3e5..b995169 100644 --- a/lib/src/flick_video_player.dart +++ b/lib/src/flick_video_player.dart @@ -74,7 +74,8 @@ class FlickVideoPlayer extends StatefulWidget { _FlickVideoPlayerState createState() => _FlickVideoPlayerState(); } -class _FlickVideoPlayerState extends State with WidgetsBindingObserver { +class _FlickVideoPlayerState extends State + with WidgetsBindingObserver { late FlickManager flickManager; bool _isFullscreen = false; OverlayEntry? _overlayEntry; @@ -95,7 +96,8 @@ class _FlickVideoPlayerState extends State with WidgetsBinding } if (kIsWeb) { - document.documentElement?.onFullscreenChange.listen(_webFullscreenListener); + document.documentElement?.onFullscreenChange + .listen(_webFullscreenListener); document.documentElement?.onKeyDown.listen(_webKeyListener); } @@ -126,7 +128,8 @@ class _FlickVideoPlayerState extends State with WidgetsBinding void listener() async { if (flickManager.flickControlManager!.isFullscreen && !_isFullscreen) { _switchToFullscreen(); - } else if (_isFullscreen && !flickManager.flickControlManager!.isFullscreen) { + } else if (_isFullscreen && + !flickManager.flickControlManager!.isFullscreen) { _exitFullscreen(); } } @@ -153,7 +156,8 @@ class _FlickVideoPlayerState extends State with WidgetsBinding return Scaffold( body: FlickManagerBuilder( flickManager: flickManager, - child: widget.flickVideoWithControlsFullscreen ?? widget.flickVideoWithControls, + child: widget.flickVideoWithControlsFullscreen ?? + widget.flickVideoWithControls, ), ); }); @@ -189,9 +193,11 @@ class _FlickVideoPlayerState extends State with WidgetsBinding _setPreferredOrientation() { // when aspect ratio is less than 1 , video will be played in portrait mode and orientation will not be changed. - var aspectRatio = widget.flickManager.flickVideoManager!.videoPlayerValue!.aspectRatio; + var aspectRatio = + widget.flickManager.flickVideoManager!.videoPlayerValue!.aspectRatio; if (_isFullscreen && aspectRatio >= 1) { - SystemChrome.setPreferredOrientations(widget.preferredDeviceOrientationFullscreen); + SystemChrome.setPreferredOrientations( + widget.preferredDeviceOrientationFullscreen); } else { SystemChrome.setPreferredOrientations(widget.preferredDeviceOrientation); } @@ -199,9 +205,11 @@ class _FlickVideoPlayerState extends State with WidgetsBinding _setSystemUIOverlays() { if (_isFullscreen) { - SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: widget.systemUIOverlayFullscreen); + SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, + overlays: widget.systemUIOverlayFullscreen); } else { - SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: widget.systemUIOverlay); + SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, + overlays: widget.systemUIOverlay); } } @@ -209,7 +217,8 @@ class _FlickVideoPlayerState extends State with WidgetsBinding final isFullscreen = (window.screenTop == 0 && window.screenY == 0); if (isFullscreen && !flickManager.flickControlManager!.isFullscreen) { flickManager.flickControlManager!.enterFullscreen(); - } else if (!isFullscreen && flickManager.flickControlManager!.isFullscreen) { + } else if (!isFullscreen && + flickManager.flickControlManager!.isFullscreen) { flickManager.flickControlManager!.exitFullscreen(); } }