fix: 旋转横屏仍有状态栏

This commit is contained in:
orz12
2024-01-22 12:54:32 +08:00
parent 103423abf7
commit 1dd70f482f

View File

@ -281,18 +281,12 @@ class _VideoDetailPageState extends State<VideoDetailPage>
final double videoHeight = MediaQuery.sizeOf(context).width * 9 / 16; final double videoHeight = MediaQuery.sizeOf(context).width * 9 / 16;
final double pinnedHeaderHeight = final double pinnedHeaderHeight =
statusBarHeight + kToolbarHeight + videoHeight; statusBarHeight + kToolbarHeight + videoHeight;
if (MediaQuery.of(context).orientation == Orientation.landscape ||
plPlayerController?.isFullScreen.value == true) {
enterFullScreen();
} else {
exitFullScreen();
}
Widget childWhenDisabled = SafeArea( Widget childWhenDisabled = SafeArea(
top: MediaQuery.of(context).orientation == Orientation.portrait && top: MediaQuery.of(context).orientation == Orientation.portrait &&
plPlayerController?.isFullScreen.value == true, plPlayerController?.isFullScreen.value == true,
bottom: MediaQuery.of(context).orientation == Orientation.portrait && bottom: MediaQuery.of(context).orientation == Orientation.portrait &&
plPlayerController?.isFullScreen.value == true, plPlayerController?.isFullScreen.value == true,
left: false,//plPlayerController?.isFullScreen.value != true, left: false, //plPlayerController?.isFullScreen.value != true,
right: false, //plPlayerController?.isFullScreen.value != true, right: false, //plPlayerController?.isFullScreen.value != true,
child: Stack( child: Stack(
children: [ children: [
@ -313,185 +307,197 @@ class _VideoDetailPageState extends State<VideoDetailPage>
(BuildContext context, bool innerBoxIsScrolled) { (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[ return <Widget>[
Obx( Obx(
() => SliverAppBar( () {
automaticallyImplyLeading: false, if (MediaQuery.of(context).orientation ==
// 假装使用一个非空变量避免Obx检测不到而罢工 Orientation.landscape ||
pinned: videoDetailController.autoPlay.value ^ plPlayerController?.isFullScreen.value == true) {
false ^ enterFullScreen();
videoDetailController.autoPlay.value, } else {
elevation: 0, exitFullScreen();
scrolledUnderElevation: 0, }
forceElevated: innerBoxIsScrolled, return SliverAppBar(
expandedHeight: MediaQuery.of(context).orientation == automaticallyImplyLeading: false,
Orientation.landscape || // 假装使用一个非空变量避免Obx检测不到而罢工
plPlayerController?.isFullScreen.value == true pinned: videoDetailController.autoPlay.value ^
? MediaQuery.sizeOf(context).height - false ^
(MediaQuery.of(context).orientation == videoDetailController.autoPlay.value,
Orientation.landscape elevation: 0,
? 0 scrolledUnderElevation: 0,
: MediaQuery.of(context).padding.top) forceElevated: innerBoxIsScrolled,
: videoHeight, expandedHeight: MediaQuery.of(context).orientation ==
backgroundColor: Colors.black, Orientation.landscape ||
flexibleSpace: FlexibleSpaceBar( plPlayerController?.isFullScreen.value == true
background: PopScope( ? MediaQuery.sizeOf(context).height -
canPop: (MediaQuery.of(context).orientation ==
plPlayerController?.isFullScreen.value != true, Orientation.landscape
onPopInvoked: (bool didPop) { ? 0
if (plPlayerController?.isFullScreen.value == : MediaQuery.of(context).padding.top)
true) { : videoHeight,
plPlayerController! backgroundColor: Colors.black,
.triggerFullScreen(status: false); flexibleSpace: FlexibleSpaceBar(
} background: PopScope(
if (MediaQuery.of(context).orientation == canPop: plPlayerController?.isFullScreen.value !=
Orientation.landscape) { true,
verticalScreen(); onPopInvoked: (bool didPop) {
} if (plPlayerController?.isFullScreen.value ==
}, true) {
child: LayoutBuilder( plPlayerController!
builder: (BuildContext context, .triggerFullScreen(status: false);
BoxConstraints boxConstraints) { }
final double maxWidth = boxConstraints.maxWidth; if (MediaQuery.of(context).orientation ==
final double maxHeight = Orientation.landscape) {
boxConstraints.maxHeight; verticalScreen();
return Stack( }
children: <Widget>[ },
if (isShowing) child: LayoutBuilder(
FutureBuilder( builder: (BuildContext context,
future: _futureBuilderFuture, BoxConstraints boxConstraints) {
builder: (BuildContext context, final double maxWidth =
AsyncSnapshot snapshot) { boxConstraints.maxWidth;
if (snapshot.hasData && final double maxHeight =
snapshot.data['status']) { boxConstraints.maxHeight;
return Obx( return Stack(
() => !videoDetailController children: <Widget>[
.autoPlay.value if (isShowing)
? nil FutureBuilder(
: PLVideoPlayer( future: _futureBuilderFuture,
controller: builder: (BuildContext context,
plPlayerController!, AsyncSnapshot snapshot) {
headerControl: if (snapshot.hasData &&
videoDetailController snapshot.data['status']) {
.headerControl, return Obx(
danmuWidget: Obx( () =>
() => PlDanmaku( !videoDetailController
key: Key( .autoPlay.value
videoDetailController ? nil
.danmakuCid : PLVideoPlayer(
.value controller:
.toString()), plPlayerController!,
cid: headerControl:
videoDetailController videoDetailController
.danmakuCid .headerControl,
.value, danmuWidget: Obx(
playerController: () => PlDanmaku(
plPlayerController!, key: Key(videoDetailController
), .danmakuCid
), .value
), .toString()),
); cid: videoDetailController
} else { .danmakuCid
return const SizedBox(); .value,
} playerController:
}, plPlayerController!,
), ),
),
),
);
} else {
return const SizedBox();
}
},
),
/// 关闭自动播放时 手动播放 /// 关闭自动播放时 手动播放
if (!videoDetailController if (!videoDetailController
.autoPlay.value) ...<Widget>[ .autoPlay.value) ...<Widget>[
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: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
handlePlay(); handlePlay();
}, },
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, 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, elevation: 0,
elevation: 0, scrolledUnderElevation: 0,
scrolledUnderElevation: 0,
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:
MaterialStateProperty Colors.transparent,
.resolveWith( actions: [
(states) { IconButton(
return Colors.white tooltip: '稍后再看',
.withOpacity(0.8); onPressed: () async {
}), var res = await UserHttp
.toViewLater(
bvid: videoDetailController
.bvid);
SmartDialog
.showToast(
res['msg']);
},
icon: const Icon(Icons
.history_outlined),
),
const SizedBox(
width: 14)
],
), ),
onPressed: () =>
handlePlay(),
icon: const Icon(
Icons.play_circle_outline,
size: 20,
),
label: const Text('轻触封面播放'),
), ),
), Positioned(
], right: 12,
)), bottom: 10,
), child: TextButton.icon(
] style: ButtonStyle(
], backgroundColor:
); MaterialStateProperty
}, .resolveWith(
)), (states) {
), return Colors.white
), .withOpacity(0.8);
}),
),
onPressed: () =>
handlePlay(),
icon: const Icon(
Icons
.play_circle_outline,
size: 20,
),
label:
const Text('轻触封面播放'),
),
),
],
)),
),
]
],
);
},
)),
),
);
},
), ),
]; ];
}, },