feat: 播放页组件嵌套拆分

This commit is contained in:
orz12
2024-04-22 20:15:07 +08:00
parent e8eee92b08
commit 493d2a32c2

View File

@@ -357,6 +357,40 @@ class _VideoDetailPageState extends State<VideoDetailPage>
@override @override
Widget build(BuildContext context) { 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( Widget childWhenDisabled = SafeArea(
top: MediaQuery.of(context).orientation == Orientation.portrait && top: MediaQuery.of(context).orientation == Orientation.portrait &&
isFullScreen.value == true, isFullScreen.value == true,
@@ -433,62 +467,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
}, },
child: Stack( child: Stack(
children: <Widget>[ children: <Widget>[
if (isShowing) if (isShowing) 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();
}
}),
/// 关闭自动播放时 手动播放 /// 关闭自动播放时 手动播放
if (!videoDetailController if (!videoDetailController
@@ -647,259 +626,196 @@ class _VideoDetailPageState extends State<VideoDetailPage>
], ],
), ),
); );
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 -
context.height * 7.690 -
context.width * 4.741;
final double videowidth = videoheight * 16 / 9;
return Row(
children: [
Column(
children: [
SizedBox(
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);
}
if (MediaQuery.of(context).orientation ==
Orientation.landscape &&
!horizontalScreen) {
verticalScreenForTwoSeconds();
}
},
child: Stack(
children: <Widget>[
if (isShowing) plPlayer,
Widget childWhenDisabledLandscape = SafeArea( /// 关闭自动播放时 手动播放
left: isFullScreen.value != true, if (!videoDetailController
right: isFullScreen.value != true, .autoPlay.value) ...<Widget>[
child: Stack(children: [ Obx(
Scaffold( () => Visibility(
resizeToAvoidBottomInset: false, visible:
key: videoDetailController.scaffoldKey, videoDetailController.isShowCover.value,
backgroundColor: Theme.of(context).colorScheme.background, child: Positioned(
appBar: PreferredSize( top: 0,
preferredSize: const Size.fromHeight(0), left: 0,
child: AppBar( right: 0,
backgroundColor: Colors.transparent, child: GestureDetector(
elevation: 0, onTap: () {
), handlePlay();
), },
body: Obx(() { child: NetworkImgLayer(
// 系数是以下三个方程(分别代表特定平板、折叠屏内屏、普通手机横屏尺寸)的近似解 type: 'emote',
// 820x+1180y+983.67z=450 src: videoDetailController
// 1812x+2176y+1985.68z=680 .videoItem['pic'],
// 1080x+2340y+1589.72z=560 width: videowidth,
final double videoheight = height: videoheight,
sqrt(context.height * context.width) * 12.555 - ),
context.height * 7.690 - ),
context.width * 4.741; ),
final double videowidth = videoheight * 16 / 9; ),
return Row( ),
children: [ Obx(
Column( () => Visibility(
children: [ visible: videoDetailController
SizedBox( .isShowCover.value &&
width: isFullScreen.value == true videoDetailController.isEffective.value,
? context.width child: Stack(
: videowidth, children: [
height: isFullScreen.value == true Positioned(
? context.height top: 0,
: videoheight, left: 0,
child: PopScope( right: 0,
canPop: isFullScreen.value != true, child: AppBar(
onPopInvoked: (bool didPop) { primary: false,
if (isFullScreen.value == true) { foregroundColor: Colors.white,
plPlayerController! elevation: 0,
.triggerFullScreen(status: false); scrolledUnderElevation: 0,
} backgroundColor: Colors.transparent,
if (MediaQuery.of(context).orientation == actions: [
Orientation.landscape && IconButton(
!horizontalScreen) { tooltip: '稍后再看',
verticalScreenForTwoSeconds(); onPressed: () async {
} var res =
}, await UserHttp.toViewLater(
child: Stack( bvid:
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 videoDetailController
.videoType == .bvid);
SearchType SmartDialog.showToast(
.video res['msg']);
? 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 (!videoDetailController
.autoPlay.value) ...<Widget>[
Obx(
() => Visibility(
visible: videoDetailController
.isShowCover.value,
child: Positioned(
top: 0,
left: 0,
right: 0,
child: GestureDetector(
onTap: () {
handlePlay();
}, },
child: NetworkImgLayer( icon: const Icon(
type: 'emote', Icons.history_outlined),
src: videoDetailController
.videoItem['pic'],
width: videowidth,
height: videoheight,
),
), ),
), const SizedBox(width: 14)
],
), ),
), ),
Obx( Positioned(
() => Visibility( right: 12,
visible: videoDetailController bottom: 10,
.isShowCover.value && child: IconButton(
videoDetailController tooltip: '播放',
.isEffective.value, onPressed: () => handlePlay(),
child: Stack( icon: Image.asset(
children: [ 'assets/images/play.png',
Positioned( width: 60,
top: 0, height: 60,
left: 0,
right: 0,
child: AppBar(
primary: false,
foregroundColor:
Colors.white,
elevation: 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: IconButton(
tooltip: '播放',
onPressed: () =>
handlePlay(),
icon: Image.asset(
'assets/images/play.png',
width: 60,
height: 60,
)),
),
],
)), )),
), ),
] ],
], )),
))), ),
SizedBox( ]
width: isFullScreen.value == true ],
? context.width ))),
: videowidth, SizedBox(
height: isFullScreen.value == true width:
? 0 isFullScreen.value == true ? context.width : videowidth,
: context.height - height: isFullScreen.value == true
videoheight - ? 0
MediaQuery.of(context).padding.top - : context.height -
MediaQuery.of(context).padding.bottom, videoheight -
child: CustomScrollView(
key: const PageStorageKey<String>('简介'),
slivers: <Widget>[
if (videoDetailController.videoType ==
SearchType.video) ...[
const VideoIntroPanel(),
] else if (videoDetailController.videoType ==
SearchType.media_bangumi) ...[
Obx(() => BangumiIntroPanel(
cid: videoDetailController.cid.value)),
]
],
))
],
),
SizedBox(
width: isFullScreen.value == true
? 0
: (context.width -
MediaQuery.of(context).padding.left -
MediaQuery.of(context).padding.right -
videowidth),
height: context.height -
MediaQuery.of(context).padding.top - MediaQuery.of(context).padding.top -
MediaQuery.of(context).padding.bottom, MediaQuery.of(context).padding.bottom,
child: TabBarView( child: CustomScrollView(
physics: const BouncingScrollPhysics(), key: PageStorageKey<String>(
controller: videoDetailController.tabCtr, '简介${videoDetailController.bvid}'),
children: <Widget>[ slivers: <Widget>[
if (videoDetailController.videoType == if (videoDetailController.videoType ==
SearchType.video) SearchType.video) ...[
const CustomScrollView( const VideoIntroPanel(),
slivers: [ ] else if (videoDetailController.videoType ==
RelatedVideoPanel(), SearchType.media_bangumi) ...[
], Obx(() => BangumiIntroPanel(
), cid: videoDetailController.cid.value)),
Obx( ]
() => VideoReplyPanel( ],
bvid: videoDetailController.bvid, ))
oid: videoDetailController.oid.value, ],
), ),
) SizedBox(
], width: isFullScreen.value == true
), ? 0
) : (context.width -
], MediaQuery.of(context).padding.left -
); MediaQuery.of(context).padding.right -
})) videowidth),
])); height: context.height -
MediaQuery.of(context).padding.top -
MediaQuery.of(context).padding.bottom,
child: TabBarView(
physics: const BouncingScrollPhysics(),
controller: videoDetailController.tabCtr,
children: <Widget>[
if (videoDetailController.videoType == SearchType.video)
const CustomScrollView(
slivers: [
RelatedVideoPanel(),
],
),
Obx(
() => VideoReplyPanel(
bvid: videoDetailController.bvid,
oid: videoDetailController.oid.value,
),
)
],
),
)
],
);
});
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( Widget childWhenEnabled = Obx(
() => !videoDetailController.autoPlay.value () => !videoDetailController.autoPlay.value
? const SizedBox() ? const SizedBox()