Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to pass OverlayState for showing the fullscreen player #282

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Format code to line length 80
  • Loading branch information
SEGVeenstra committed Jul 12, 2024
commit 5769374c95f504ea251e456e7b83e9071ad925fe
27 changes: 18 additions & 9 deletions lib/src/flick_video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class FlickVideoPlayer extends StatefulWidget {
_FlickVideoPlayerState createState() => _FlickVideoPlayerState();
}

class _FlickVideoPlayerState extends State<FlickVideoPlayer> with WidgetsBindingObserver {
class _FlickVideoPlayerState extends State<FlickVideoPlayer>
with WidgetsBindingObserver {
late FlickManager flickManager;
bool _isFullscreen = false;
OverlayEntry? _overlayEntry;
Expand All @@ -95,7 +96,8 @@ class _FlickVideoPlayerState extends State<FlickVideoPlayer> with WidgetsBinding
}

if (kIsWeb) {
document.documentElement?.onFullscreenChange.listen(_webFullscreenListener);
document.documentElement?.onFullscreenChange
.listen(_webFullscreenListener);
document.documentElement?.onKeyDown.listen(_webKeyListener);
}

Expand Down Expand Up @@ -126,7 +128,8 @@ class _FlickVideoPlayerState extends State<FlickVideoPlayer> with WidgetsBinding
void listener() async {
if (flickManager.flickControlManager!.isFullscreen && !_isFullscreen) {
_switchToFullscreen();
} else if (_isFullscreen && !flickManager.flickControlManager!.isFullscreen) {
} else if (_isFullscreen &&
!flickManager.flickControlManager!.isFullscreen) {
_exitFullscreen();
}
}
Expand All @@ -153,7 +156,8 @@ class _FlickVideoPlayerState extends State<FlickVideoPlayer> with WidgetsBinding
return Scaffold(
body: FlickManagerBuilder(
flickManager: flickManager,
child: widget.flickVideoWithControlsFullscreen ?? widget.flickVideoWithControls,
child: widget.flickVideoWithControlsFullscreen ??
widget.flickVideoWithControls,
),
);
});
Expand Down Expand Up @@ -189,27 +193,32 @@ class _FlickVideoPlayerState extends State<FlickVideoPlayer> 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);
}
}

_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);
}
}

void _webFullscreenListener(Event event) {
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();
}
}
Expand Down