From 9d1bba8a346da7750a5720509166b2ebf41e5d82 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Fri, 6 Dec 2024 23:54:18 +0800 Subject: [PATCH] opt: fullScreen logic --- lib/pages/video/detail/view.dart | 74 ++++++++++++++++---------------- lib/plugin/pl_player/view.dart | 2 + 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index 0ec777c4..96a06fa6 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -502,7 +502,7 @@ class _VideoDetailPageState extends State @override Widget build(BuildContext context) { final sizeContext = MediaQuery.sizeOf(context); - final _context = MediaQuery.of(context); + final orientation = MediaQuery.orientationOf(context); late final double verticalHeight = sizeContext.width * 22 / 16; late double defaultVideoHeight = vdCtr.videoDirection.value == 'vertical' ? verticalHeight @@ -517,12 +517,12 @@ class _VideoDetailPageState extends State }); // 竖屏 - final bool isPortrait = _context.orientation == Orientation.portrait; + final bool isPortrait = orientation == Orientation.portrait; // 横屏 - final bool isLandscape = _context.orientation == Orientation.landscape; + final bool isLandscape = orientation == Orientation.landscape; final Rx isFullScreen = plPlayerController?.isFullScreen ?? false.obs; // 全屏时高度撑满 - if (isLandscape || isFullScreen.value == true) { + if (isLandscape || isFullScreen.value) { videoHeight.value = Get.size.height; enterFullScreen(); } else { @@ -634,10 +634,8 @@ class _VideoDetailPageState extends State } Widget childWhenDisabled = SafeArea( - top: MediaQuery.of(context).orientation == Orientation.portrait && - plPlayerController?.isFullScreen.value == true, - bottom: MediaQuery.of(context).orientation == Orientation.portrait && - plPlayerController?.isFullScreen.value == true, + top: isPortrait && isFullScreen.value, + bottom: isPortrait && isFullScreen.value, left: false, right: false, child: Stack( @@ -660,22 +658,25 @@ class _VideoDetailPageState extends State return [ Obx( () { - final Orientation orientation = - MediaQuery.of(context).orientation; + final bool isLandscape = + MediaQuery.orientationOf(context) == + Orientation.landscape; final bool isFullScreen = - plPlayerController?.isFullScreen.value == true; - final double expandedHeight = - orientation == Orientation.landscape || isFullScreen - ? (MediaQuery.sizeOf(context).height - - (orientation == Orientation.landscape - ? 0 - : MediaQuery.of(context).padding.top)) - : videoHeight.value; - if (orientation == Orientation.landscape || - isFullScreen) { + plPlayerController?.isFullScreen.value ?? false; + + late double expandedHeight; + if (isLandscape || isFullScreen) { enterFullScreen(); + expandedHeight = (MediaQuery.sizeOf(context).height - + (isLandscape + ? 0 + : MediaQuery.paddingOf(context).top)); } else { exitFullScreen(); + if (vdCtr.videoDirection.value == 'vertical') { + videoHeight.value = verticalHeight; + } + expandedHeight = videoHeight.value; } return SliverAppBar( automaticallyImplyLeading: false, @@ -687,21 +688,24 @@ class _VideoDetailPageState extends State backgroundColor: Colors.black, flexibleSpace: SizedBox.expand( child: PopScope( - canPop: - plPlayerController?.isFullScreen.value != true, + canPop: !isFullScreen, onPopInvoked: (bool didPop) { - if (plPlayerController?.controlsLock.value == - true) { - plPlayerController?.onLockControl(false); - return; + if (plPlayerController != null) { + if (plPlayerController!.controlsLock.value) { + plPlayerController!.onLockControl(false); + return; + } + if (isFullScreen) { + plPlayerController! + .triggerFullScreen(status: false); + if (vdCtr.videoDirection.value == + 'vertical') { + videoHeight.value = verticalHeight; + } + } } - if (plPlayerController?.isFullScreen.value == - true) { - plPlayerController! - .triggerFullScreen(status: false); - } - if (MediaQuery.of(context).orientation == - Orientation.landscape) { + + if (isLandscape) { verticalScreen(); } }, @@ -746,9 +750,7 @@ class _VideoDetailPageState extends State /// 不收回 pinnedHeaderSliverHeightBuilder: () { - return MediaQuery.of(context).orientation == - Orientation.landscape || - plPlayerController?.isFullScreen.value == true + return isLandscape || isFullScreen.value ? MediaQuery.sizeOf(context).height : playerStatus.value != PlayerStatus.playing ? kToolbarHeight diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index b47d38de..3bc6b288 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -732,6 +732,7 @@ class _PLVideoPlayerState extends State lastFullScreenToggleTime = DateTime.now(); // 下滑退出全屏 await widget.controller.triggerFullScreen(status: flag); + widget.fullScreenCb?.call(flag); } _distance.value = 0.0; } else if (dy < _distance.value && @@ -741,6 +742,7 @@ class _PLVideoPlayerState extends State lastFullScreenToggleTime = DateTime.now(); // 上滑进入全屏 await widget.controller.triggerFullScreen(status: !flag); + widget.fullScreenCb?.call(!flag); } _distance.value = 0.0; }