mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: 播放页组件嵌套拆分
This commit is contained in:
@@ -357,6 +357,40 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget plPlayer = FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||
if (snapshot.hasData && snapshot.data['status']) {
|
||||
return Obx(
|
||||
() => !videoDetailController.autoPlay.value ||
|
||||
plPlayerController == null ||
|
||||
plPlayerController!.videoController == null
|
||||
? nil
|
||||
: PLVideoPlayer(
|
||||
controller: plPlayerController!,
|
||||
videoIntroController:
|
||||
videoDetailController.videoType == SearchType.video
|
||||
? videoIntroController
|
||||
: null,
|
||||
bangumiIntroController: videoDetailController.videoType ==
|
||||
SearchType.media_bangumi
|
||||
? bangumiIntroController
|
||||
: null,
|
||||
headerControl: videoDetailController.headerControl,
|
||||
danmuWidget: Obx(
|
||||
() => PlDanmaku(
|
||||
key: Key(videoDetailController.danmakuCid.value
|
||||
.toString()),
|
||||
cid: videoDetailController.danmakuCid.value,
|
||||
playerController: plPlayerController!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
});
|
||||
Widget childWhenDisabled = SafeArea(
|
||||
top: MediaQuery.of(context).orientation == Orientation.portrait &&
|
||||
isFullScreen.value == true,
|
||||
@@ -433,62 +467,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
},
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
if (isShowing)
|
||||
FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot snapshot) {
|
||||
if (snapshot.hasData &&
|
||||
snapshot.data['status']) {
|
||||
return Obx(
|
||||
() => !videoDetailController
|
||||
.autoPlay.value ||
|
||||
plPlayerController ==
|
||||
null ||
|
||||
plPlayerController!
|
||||
.videoController ==
|
||||
null
|
||||
? nil
|
||||
: PLVideoPlayer(
|
||||
controller:
|
||||
plPlayerController!,
|
||||
videoIntroController:
|
||||
videoDetailController
|
||||
.videoType ==
|
||||
SearchType.video
|
||||
? videoIntroController
|
||||
: null,
|
||||
bangumiIntroController:
|
||||
videoDetailController
|
||||
.videoType ==
|
||||
SearchType
|
||||
.media_bangumi
|
||||
? bangumiIntroController
|
||||
: null,
|
||||
headerControl:
|
||||
videoDetailController
|
||||
.headerControl,
|
||||
danmuWidget: Obx(
|
||||
() => PlDanmaku(
|
||||
key: Key(
|
||||
videoDetailController
|
||||
.danmakuCid
|
||||
.value
|
||||
.toString()),
|
||||
cid:
|
||||
videoDetailController
|
||||
.danmakuCid
|
||||
.value,
|
||||
playerController:
|
||||
plPlayerController!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
}),
|
||||
if (isShowing) plPlayer,
|
||||
|
||||
/// 关闭自动播放时 手动播放
|
||||
if (!videoDetailController
|
||||
@@ -647,29 +626,12 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget childWhenDisabledLandscape = SafeArea(
|
||||
left: isFullScreen.value != true,
|
||||
right: isFullScreen.value != true,
|
||||
child: Stack(children: [
|
||||
Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
key: videoDetailController.scaffoldKey,
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
appBar: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(0),
|
||||
child: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
body: Obx(() {
|
||||
Widget childWhenDisabledLandscapeInner = Obx(() {
|
||||
// 系数是以下三个方程(分别代表特定平板、折叠屏内屏、普通手机横屏尺寸)的近似解
|
||||
// 820x+1180y+983.67z=450
|
||||
// 1812x+2176y+1985.68z=680
|
||||
// 1080x+2340y+1589.72z=560
|
||||
final double videoheight =
|
||||
sqrt(context.height * context.width) * 12.555 -
|
||||
final double videoheight = sqrt(context.height * context.width) * 12.555 -
|
||||
context.height * 7.690 -
|
||||
context.width * 4.741;
|
||||
final double videowidth = videoheight * 16 / 9;
|
||||
@@ -678,18 +640,15 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: isFullScreen.value == true
|
||||
? context.width
|
||||
: videowidth,
|
||||
height: isFullScreen.value == true
|
||||
? context.height
|
||||
: videoheight,
|
||||
width:
|
||||
isFullScreen.value == true ? context.width : videowidth,
|
||||
height:
|
||||
isFullScreen.value == true ? context.height : videoheight,
|
||||
child: PopScope(
|
||||
canPop: isFullScreen.value != true,
|
||||
onPopInvoked: (bool didPop) {
|
||||
if (isFullScreen.value == true) {
|
||||
plPlayerController!
|
||||
.triggerFullScreen(status: false);
|
||||
plPlayerController!.triggerFullScreen(status: false);
|
||||
}
|
||||
if (MediaQuery.of(context).orientation ==
|
||||
Orientation.landscape &&
|
||||
@@ -699,71 +658,15 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
},
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
if (isShowing)
|
||||
FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot snapshot) {
|
||||
if (snapshot.hasData &&
|
||||
snapshot.data['status']) {
|
||||
return Obx(
|
||||
() => !videoDetailController
|
||||
.autoPlay.value ||
|
||||
plPlayerController ==
|
||||
null ||
|
||||
plPlayerController!
|
||||
.videoController ==
|
||||
null
|
||||
? nil
|
||||
: PLVideoPlayer(
|
||||
controller:
|
||||
plPlayerController!,
|
||||
videoIntroController:
|
||||
videoDetailController
|
||||
.videoType ==
|
||||
SearchType
|
||||
.video
|
||||
? videoIntroController
|
||||
: null,
|
||||
bangumiIntroController:
|
||||
videoDetailController
|
||||
.videoType ==
|
||||
SearchType
|
||||
.media_bangumi
|
||||
? bangumiIntroController
|
||||
: null,
|
||||
headerControl:
|
||||
videoDetailController
|
||||
.headerControl,
|
||||
danmuWidget: Obx(
|
||||
() => PlDanmaku(
|
||||
key: Key(
|
||||
videoDetailController
|
||||
.danmakuCid
|
||||
.value
|
||||
.toString()),
|
||||
cid:
|
||||
videoDetailController
|
||||
.danmakuCid
|
||||
.value,
|
||||
playerController:
|
||||
plPlayerController!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
}),
|
||||
if (isShowing) plPlayer,
|
||||
|
||||
/// 关闭自动播放时 手动播放
|
||||
if (!videoDetailController
|
||||
.autoPlay.value) ...<Widget>[
|
||||
Obx(
|
||||
() => Visibility(
|
||||
visible: videoDetailController
|
||||
.isShowCover.value,
|
||||
visible:
|
||||
videoDetailController.isShowCover.value,
|
||||
child: Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
@@ -787,8 +690,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
() => Visibility(
|
||||
visible: videoDetailController
|
||||
.isShowCover.value &&
|
||||
videoDetailController
|
||||
.isEffective.value,
|
||||
videoDetailController.isEffective.value,
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
@@ -797,26 +699,24 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
right: 0,
|
||||
child: AppBar(
|
||||
primary: false,
|
||||
foregroundColor:
|
||||
Colors.white,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
backgroundColor:
|
||||
Colors.transparent,
|
||||
backgroundColor: Colors.transparent,
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '稍后再看',
|
||||
onPressed: () async {
|
||||
var res = await UserHttp
|
||||
.toViewLater(
|
||||
var res =
|
||||
await UserHttp.toViewLater(
|
||||
bvid:
|
||||
videoDetailController
|
||||
.bvid);
|
||||
SmartDialog.showToast(
|
||||
res['msg']);
|
||||
},
|
||||
icon: const Icon(Icons
|
||||
.history_outlined),
|
||||
icon: const Icon(
|
||||
Icons.history_outlined),
|
||||
),
|
||||
const SizedBox(width: 14)
|
||||
],
|
||||
@@ -827,8 +727,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
bottom: 10,
|
||||
child: IconButton(
|
||||
tooltip: '播放',
|
||||
onPressed: () =>
|
||||
handlePlay(),
|
||||
onPressed: () => handlePlay(),
|
||||
icon: Image.asset(
|
||||
'assets/images/play.png',
|
||||
width: 60,
|
||||
@@ -842,9 +741,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
],
|
||||
))),
|
||||
SizedBox(
|
||||
width: isFullScreen.value == true
|
||||
? context.width
|
||||
: videowidth,
|
||||
width:
|
||||
isFullScreen.value == true ? context.width : videowidth,
|
||||
height: isFullScreen.value == true
|
||||
? 0
|
||||
: context.height -
|
||||
@@ -852,7 +750,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
MediaQuery.of(context).padding.top -
|
||||
MediaQuery.of(context).padding.bottom,
|
||||
child: CustomScrollView(
|
||||
key: const PageStorageKey<String>('简介'),
|
||||
key: PageStorageKey<String>(
|
||||
'简介${videoDetailController.bvid}'),
|
||||
slivers: <Widget>[
|
||||
if (videoDetailController.videoType ==
|
||||
SearchType.video) ...[
|
||||
@@ -880,8 +779,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
physics: const BouncingScrollPhysics(),
|
||||
controller: videoDetailController.tabCtr,
|
||||
children: <Widget>[
|
||||
if (videoDetailController.videoType ==
|
||||
SearchType.video)
|
||||
if (videoDetailController.videoType == SearchType.video)
|
||||
const CustomScrollView(
|
||||
slivers: [
|
||||
RelatedVideoPanel(),
|
||||
@@ -898,8 +796,26 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
)
|
||||
],
|
||||
);
|
||||
}))
|
||||
]));
|
||||
});
|
||||
Widget childWhenDisabledLandscape = Container(
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
child: SafeArea(
|
||||
left: isFullScreen.value != true,
|
||||
right: isFullScreen.value != true,
|
||||
child: Stack(children: [
|
||||
Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
key: videoDetailController.scaffoldKey,
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
appBar: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(0),
|
||||
child: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
body: childWhenDisabledLandscapeInner)
|
||||
])));
|
||||
Widget childWhenEnabled = Obx(
|
||||
() => !videoDetailController.autoPlay.value
|
||||
? const SizedBox()
|
||||
|
||||
Reference in New Issue
Block a user