fix: 修正非自动播放下空检查问题

This commit is contained in:
orz12
2023-12-22 14:18:21 +08:00
parent e32ddeaec0
commit eb8feb5773

View File

@ -237,17 +237,17 @@ class _VideoDetailPageState extends State<VideoDetailPage>
final double pinnedHeaderHeight = final double pinnedHeaderHeight =
statusBarHeight + kToolbarHeight + videoHeight; statusBarHeight + kToolbarHeight + videoHeight;
if (MediaQuery.of(context).orientation == Orientation.landscape || if (MediaQuery.of(context).orientation == Orientation.landscape ||
plPlayerController!.isFullScreen.value) { plPlayerController?.isFullScreen.value == true) {
enterFullScreen(); enterFullScreen();
} else { } else {
exitFullScreen(); exitFullScreen();
} }
Widget childWhenDisabled = SafeArea( Widget childWhenDisabled = SafeArea(
top: MediaQuery.of(context).orientation == Orientation.portrait, top: MediaQuery.of(context).orientation == Orientation.portrait,
bottom: MediaQuery.of(context).orientation == Orientation.portrait bottom: MediaQuery.of(context).orientation == Orientation.portrait &&
&& plPlayerController!.isFullScreen.value, plPlayerController?.isFullScreen.value == true,
left: !plPlayerController!.isFullScreen.value, left: plPlayerController?.isFullScreen.value != true,
right: !plPlayerController!.isFullScreen.value, right: plPlayerController?.isFullScreen.value != true,
child: Stack( child: Stack(
children: [ children: [
Scaffold( Scaffold(
@ -259,169 +259,168 @@ class _VideoDetailPageState extends State<VideoDetailPage>
headerSliverBuilder: headerSliverBuilder:
(BuildContext context, bool innerBoxIsScrolled) { (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[ return <Widget>[
Obx(() => PopScope( SliverAppBar(
canPop: !plPlayerController!.isFullScreen.value, automaticallyImplyLeading: false,
onPopInvoked: (bool didPop) { pinned: false,
if (plPlayerController!.isFullScreen.value) { elevation: 0,
plPlayerController! scrolledUnderElevation: 0,
.triggerFullScreen(status: false); forceElevated: innerBoxIsScrolled,
} expandedHeight:
if (MediaQuery.of(context).orientation == plPlayerController?.isFullScreen.value == true ||
Orientation.landscape) { MediaQuery.of(context).orientation ==
verticalScreen(); Orientation.landscape
} ? MediaQuery.of(context).size.height -
}, (MediaQuery.of(context).orientation ==
child: SliverAppBar( Orientation.landscape
automaticallyImplyLeading: false, ? 0
pinned: false, : statusBarHeight)
elevation: 0, : videoHeight,
scrolledUnderElevation: 0, backgroundColor: Colors.black,
forceElevated: innerBoxIsScrolled, flexibleSpace: FlexibleSpaceBar(
expandedHeight: background: PopScope(
plPlayerController!.isFullScreen.value || canPop:
MediaQuery.of(context).orientation == plPlayerController?.isFullScreen.value != true,
Orientation.landscape onPopInvoked: (bool didPop) {
? MediaQuery.of(context).size.height - if (plPlayerController?.isFullScreen.value ==
(MediaQuery.of(context).orientation == true) {
Orientation.landscape plPlayerController!
? 0 .triggerFullScreen(status: false);
: statusBarHeight) }
: videoHeight, if (MediaQuery.of(context).orientation ==
backgroundColor: Colors.black, Orientation.landscape) {
flexibleSpace: FlexibleSpaceBar( verticalScreen();
background: LayoutBuilder( }
builder: (context, boxConstraints) { },
double maxWidth = boxConstraints.maxWidth; child: LayoutBuilder(
double maxHeight = boxConstraints.maxHeight; builder: (context, boxConstraints) {
return Stack( double maxWidth = boxConstraints.maxWidth;
children: [ double maxHeight = boxConstraints.maxHeight;
FutureBuilder( return Stack(
future: _futureBuilderFuture, children: [
builder: ((context, snapshot) { FutureBuilder(
if (snapshot.hasData && future: _futureBuilderFuture,
snapshot.data['status']) { builder: ((context, snapshot) {
return Obx( if (snapshot.hasData &&
() => !videoDetailController snapshot.data['status']) {
.autoPlay.value return Obx(
? const SizedBox() () => !videoDetailController
: PLVideoPlayer( .autoPlay.value
controller: ? const SizedBox()
plPlayerController!, : PLVideoPlayer(
headerControl: controller:
videoDetailController plPlayerController!,
.headerControl, headerControl:
danmuWidget: Obx( videoDetailController
() => PlDanmaku( .headerControl,
key: Key( danmuWidget: Obx(
videoDetailController () => PlDanmaku(
.danmakuCid key: Key(
.value videoDetailController
.toString()), .danmakuCid
cid: .value
videoDetailController .toString()),
.danmakuCid cid:
.value, videoDetailController
playerController: .danmakuCid
plPlayerController!, .value,
), playerController:
plPlayerController!,
), ),
), ),
); ),
} else { );
return const SizedBox(); } else {
} return const SizedBox();
}), }
), }),
),
Obx( Obx(
() => Visibility( () => Visibility(
visible: videoDetailController visible: videoDetailController
.isShowCover.value, .isShowCover.value,
child: Positioned( child: Positioned(
top: 0, top: 0,
left: 0, left: 0,
right: 0, right: 0,
child: NetworkImgLayer( child: NetworkImgLayer(
type: 'emote', type: 'emote',
src: videoDetailController src: videoDetailController
.videoItem['pic'], .videoItem['pic'],
width: maxWidth, width: maxWidth,
height: maxHeight, height: maxHeight,
),
), ),
), ),
), ),
),
/// 关闭自动播放时 手动播放 /// 关闭自动播放时 手动播放
Obx( Obx(
() => Visibility( () => Visibility(
visible: videoDetailController visible: videoDetailController
.isShowCover.value && .isShowCover.value &&
videoDetailController videoDetailController
.isEffective.value && .isEffective.value &&
!videoDetailController !videoDetailController
.autoPlay.value, .autoPlay.value,
child: Stack( child: Stack(
children: [ children: [
Positioned( Positioned(
top: 0, top: 0,
left: 0, left: 0,
right: 0, right: 0,
child: AppBar( child: AppBar(
primary: false, primary: false,
foregroundColor: foregroundColor: Colors.white,
Colors.white, backgroundColor:
Colors.transparent,
actions: [
IconButton(
tooltip: '稍后再看',
onPressed: () async {
var res = await UserHttp
.toViewLater(
bvid:
videoDetailController
.bvid);
SmartDialog.showToast(
res['msg']);
},
icon: const Icon(Icons
.history_outlined),
),
const SizedBox(width: 14)
],
),
),
Positioned(
right: 12,
bottom: 10,
child: TextButton.icon(
style: ButtonStyle(
backgroundColor: backgroundColor:
Colors.transparent, MaterialStateProperty
actions: [ .resolveWith(
IconButton( (states) {
tooltip: '稍后再看', return Theme.of(context)
onPressed: () async { .colorScheme
var res = await UserHttp .primaryContainer;
.toViewLater( }),
bvid:
videoDetailController
.bvid);
SmartDialog.showToast(
res['msg']);
},
icon: const Icon(Icons
.history_outlined),
),
const SizedBox(width: 14)
],
), ),
), onPressed: () => handlePlay(),
Positioned( icon: const Icon(
right: 12, Icons.play_circle_outline,
bottom: 10, size: 20,
child: TextButton.icon(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty
.resolveWith(
(states) {
return Theme.of(context)
.colorScheme
.primaryContainer;
}),
),
onPressed: () =>
handlePlay(),
icon: const Icon(
Icons.play_circle_outline,
size: 20,
),
label: const Text('Play'),
), ),
label: const Text('Play'),
), ),
], ),
)), ],
), )),
], ),
); ],
}, );
), },
)), )),
)), )),
]; ];
@ -433,8 +432,9 @@ class _VideoDetailPageState extends State<VideoDetailPage>
// }, // },
/// 不收回 /// 不收回
pinnedHeaderSliverHeightBuilder: () { pinnedHeaderSliverHeightBuilder: () {
return plPlayerController!.isFullScreen.value ? return plPlayerController?.isFullScreen.value == true
MediaQuery.of(context).size.height: pinnedHeaderHeight; ? MediaQuery.of(context).size.height
: pinnedHeaderHeight;
}, },
onlyOneScrollInBody: true, onlyOneScrollInBody: true,
body: Container( body: Container(