diff --git a/lib/common/widgets/list_sheet.dart b/lib/common/widgets/list_sheet.dart index 0fa7752c2..79b7cd682 100644 --- a/lib/common/widgets/list_sheet.dart +++ b/lib/common/widgets/list_sheet.dart @@ -7,7 +7,6 @@ import 'package:PiliPalaX/models/bangumi/info.dart' as bangumi; import 'package:PiliPalaX/models/video_detail_res.dart' as video; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; -import 'package:get/get.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; @@ -24,6 +23,7 @@ class ListSheetContent extends StatefulWidget { this.aid, required this.currentCid, required this.changeFucCall, + required this.onClose, }); final dynamic index; @@ -33,6 +33,7 @@ class ListSheetContent extends StatefulWidget { final int? aid; final int currentCid; final Function changeFucCall; + final VoidCallback onClose; @override State createState() => _ListSheetContentState(); @@ -136,7 +137,7 @@ class _ListSheetContentState extends State } } SmartDialog.showToast('切换到:$title'); - Get.back(); + widget.onClose(); widget.changeFucCall( episode is bangumi.EpisodeItem ? episode.epId : null, episode.runtimeType.toString() == "EpisodeItem" @@ -326,7 +327,7 @@ class _ListSheetContentState extends State _mediumButton( tooltip: '关闭', icon: Icons.close, - onPressed: Get.back, + onPressed: widget.onClose, ), ], ), diff --git a/lib/pages/video/detail/controller.dart b/lib/pages/video/detail/controller.dart index 1c26ddc6f..39d028ec8 100644 --- a/lib/pages/video/detail/controller.dart +++ b/lib/pages/video/detail/controller.dart @@ -214,6 +214,8 @@ class VideoDetailController extends GetxController PlayerStatus? playerStatus; StreamSubscription? positionSubscription; + PersistentBottomSheetController? bsController; + @override void onInit() { super.onInit(); @@ -1043,15 +1045,17 @@ class VideoDetailController extends GetxController ), ); } - plPlayerController.isFullScreen.value - ? scaffoldKey.currentState?.showBottomSheet( - enableDrag: false, - (context) => _postPanel(false), - ) - : childKey.currentState?.showBottomSheet( - enableDrag: false, - (context) => _postPanel(), - ); + if (plPlayerController.isFullScreen.value) { + bsController = scaffoldKey.currentState?.showBottomSheet( + enableDrag: false, + (context) => _postPanel(false), + ); + } else { + childKey.currentState?.showBottomSheet( + enableDrag: false, + (context) => _postPanel(), + ); + } } Widget _postPanel([bool isChild = true]) => StatefulBuilder( @@ -1206,7 +1210,14 @@ class VideoDetailController extends GetxController iconButton( context: context, tooltip: '关闭', - onPressed: Get.back, + onPressed: () { + if (bsController != null) { + bsController!.close(); + bsController = null; + } else { + Get.back(); + } + }, icon: Icons.close, ), const SizedBox(width: 16), diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index d0caa3967..05ff71a26 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -541,23 +541,7 @@ class _VideoDetailPageState extends State (horizontalScreen || MediaQuery.of(context).orientation == Orientation.portrait), - onPopInvokedWithResult: - (bool didPop, Object? result) { - if (plPlayerController?.controlsLock.value == - true) { - plPlayerController?.onLockControl(false); - return; - } - if (isFullScreen) { - plPlayerController! - .triggerFullScreen(status: false); - } - if (MediaQuery.of(context).orientation == - Orientation.landscape && - !horizontalScreen) { - verticalScreenForTwoSeconds(); - } - }, + onPopInvokedWithResult: _onPopInvokedWithResult, child: videoPlayer(videoWidth, videoHeight), ), ); @@ -608,20 +592,7 @@ class _VideoDetailPageState extends State width: isFullScreen ? context.width : videoWidth, child: PopScope( canPop: !isFullScreen, - onPopInvokedWithResult: (bool didPop, Object? result) { - if (plPlayerController?.controlsLock.value == true) { - plPlayerController?.onLockControl(false); - return; - } - if (isFullScreen) { - plPlayerController!.triggerFullScreen(status: false); - } - if (MediaQuery.of(context).orientation == - Orientation.landscape && - !horizontalScreen) { - verticalScreenForTwoSeconds(); - } - }, + onPopInvokedWithResult: _onPopInvokedWithResult, child: videoPlayer(videoWidth, videoHeight), ), ), @@ -664,20 +635,7 @@ class _VideoDetailPageState extends State : videoHeight, child: PopScope( canPop: !isFullScreen, - onPopInvokedWithResult: (bool didPop, Object? result) { - if (plPlayerController?.controlsLock.value == true) { - plPlayerController?.onLockControl(false); - return; - } - if (isFullScreen) { - plPlayerController!.triggerFullScreen(status: false); - } - if (MediaQuery.of(context).orientation == - Orientation.landscape && - !horizontalScreen) { - verticalScreenForTwoSeconds(); - } - }, + onPopInvokedWithResult: _onPopInvokedWithResult, child: videoPlayer(videoWidth, videoHeight), ), ), @@ -722,20 +680,7 @@ class _VideoDetailPageState extends State width: isFullScreen ? context.width : videoWidth, child: PopScope( canPop: !isFullScreen, - onPopInvokedWithResult: (bool didPop, Object? result) { - if (plPlayerController?.controlsLock.value == true) { - plPlayerController?.onLockControl(false); - return; - } - if (isFullScreen) { - plPlayerController!.triggerFullScreen(status: false); - } - if (MediaQuery.of(context).orientation == - Orientation.landscape && - !horizontalScreen) { - verticalScreenForTwoSeconds(); - } - }, + onPopInvokedWithResult: _onPopInvokedWithResult, child: videoPlayer(videoWidth, videoHeight), ), ), @@ -803,20 +748,7 @@ class _VideoDetailPageState extends State height: isFullScreen ? context.height : videoHeight, child: PopScope( canPop: !isFullScreen, - onPopInvokedWithResult: (bool didPop, Object? result) { - if (plPlayerController?.controlsLock.value == true) { - plPlayerController?.onLockControl(false); - return; - } - if (isFullScreen) { - plPlayerController!.triggerFullScreen(status: false); - } - if (MediaQuery.of(context).orientation == - Orientation.landscape && - !horizontalScreen) { - verticalScreenForTwoSeconds(); - } - }, + onPopInvokedWithResult: _onPopInvokedWithResult, child: videoPlayer(videoWidth, videoHeight), ), ), @@ -1408,9 +1340,18 @@ class _VideoDetailPageState extends State videoDetailController.videoType == SearchType.media_bangumi ? bangumiIntroController.changeSeasonOrbangu : videoIntroController.changeSeasonOrbangu, + onClose: () { + if (videoDetailController.bsController != null) { + videoDetailController.bsController!.close(); + videoDetailController.bsController = null; + } else { + Get.back(); + } + }, ); if (isFullScreen) { - videoDetailController.scaffoldKey.currentState?.showBottomSheet( + videoDetailController.bsController = + videoDetailController.scaffoldKey.currentState?.showBottomSheet( (context) => listSheetContent(), ); } else { @@ -1463,7 +1404,14 @@ class _VideoDetailPageState extends State size: 30, icon: Icons.clear, tooltip: '关闭', - onPressed: Get.back, + onPressed: () { + if (videoDetailController.bsController != null) { + videoDetailController.bsController!.close(); + videoDetailController.bsController = null; + } else { + Get.back(); + } + }, ), const SizedBox(width: 16), ], @@ -1565,7 +1513,8 @@ class _VideoDetailPageState extends State } if (isFullScreen) { - videoDetailController.scaffoldKey.currentState?.showBottomSheet( + videoDetailController.bsController = + videoDetailController.scaffoldKey.currentState?.showBottomSheet( (context) => listSheetContent(context, true), ); } else { @@ -1574,4 +1523,23 @@ class _VideoDetailPageState extends State ); } } + + void _onPopInvokedWithResult(didPop, result) { + if (videoDetailController.bsController != null) { + videoDetailController.bsController!.close(); + videoDetailController.bsController = null; + return; + } + if (plPlayerController?.controlsLock.value == true) { + plPlayerController?.onLockControl(false); + return; + } + if (isFullScreen) { + plPlayerController!.triggerFullScreen(status: false); + } + if (MediaQuery.of(context).orientation == Orientation.landscape && + !horizontalScreen) { + verticalScreenForTwoSeconds(); + } + } }