mod: horizontal live room

Closes #62

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-02-23 16:59:46 +08:00
parent 16de044d3d
commit 14129e8f21
3 changed files with 306 additions and 222 deletions

View File

@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:PiliPlus/http/live.dart';
import 'package:PiliPlus/pages/live_room/widgets/chat.dart';
@@ -73,11 +74,11 @@ class _LiveRoomPageState extends State<LiveRoomPage>
_updateFontSize();
}
});
WidgetsBinding.instance.addPostFrameCallback((_) {
if (context.orientation == Orientation.landscape) {
plPlayerController.triggerFullScreen(status: true);
}
});
// WidgetsBinding.instance.addPostFrameCallback((_) {
// if (context.orientation == Orientation.landscape) {
// plPlayerController.triggerFullScreen(status: true);
// }
// });
}
void _updateFontSize() async {
@@ -130,12 +131,18 @@ class _LiveRoomPageState extends State<LiveRoomPage>
}
}
Widget get videoPlayerPanel {
final GlobalKey videoPlayerKey = GlobalKey();
final GlobalKey playerKey = GlobalKey();
Widget videoPlayerPanel([Color? fill]) {
return FutureBuilder(
key: videoPlayerKey,
future: _futureBuilderFuture,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData && snapshot.data['status']) {
return PLVideoPlayer(
key: playerKey,
fill: fill,
plPlayerController: plPlayerController,
bottomControl: BottomControl(
controller: plPlayerController,
@@ -176,11 +183,10 @@ class _LiveRoomPageState extends State<LiveRoomPage>
);
}
Widget get childWhenDisabled {
return Scaffold(
primary: true,
backgroundColor: Colors.black,
body: Stack(
Widget childWhenDisabled(bool isPortrait) {
return ColoredBox(
color: Colors.black,
child: Stack(
children: [
Positioned(
left: 0,
@@ -221,16 +227,56 @@ class _LiveRoomPageState extends State<LiveRoomPage>
: const SizedBox(),
),
),
Column(
isPortrait
? Scaffold(
backgroundColor: Colors.transparent,
body: Column(
children: [
AppBar(
_buildAppBar,
..._buildBodyP,
],
),
)
: Column(
children: [
_buildAppBar,
_buildBodyH,
],
),
],
),
);
}
@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_updateFontSize();
});
return OrientationBuilder(
builder: (BuildContext context, Orientation orientation) {
if (Platform.isAndroid) {
return PiPSwitcher(
getChildWhenDisabled: () =>
childWhenDisabled(orientation == Orientation.portrait),
getChildWhenEnabled: () => videoPlayerPanel,
floating: floating,
);
} else {
return childWhenDisabled(orientation == Orientation.portrait);
}
},
);
}
Color get _color => Color(0xFFEEEEEE);
Widget get _buildAppBar => AppBar(
backgroundColor: Colors.transparent,
foregroundColor: Colors.white,
titleTextStyle: TextStyle(color: Colors.white),
toolbarHeight:
MediaQuery.of(context).orientation == Orientation.portrait
? 56
: 0,
MediaQuery.of(context).orientation == Orientation.portrait ? 56 : 0,
title: FutureBuilder(
future: _futureBuilder,
builder: (context, snapshot) {
@@ -245,8 +291,8 @@ class _LiveRoomPageState extends State<LiveRoomPage>
GestureDetector(
onTap: () {
_node.unfocus();
dynamic uid = _liveRoomController
.roomInfoH5.value.roomInfo?.uid;
dynamic uid =
_liveRoomController.roomInfoH5.value.roomInfo?.uid;
Get.toNamed(
'/member?mid=$uid',
arguments: {
@@ -258,8 +304,8 @@ class _LiveRoomPageState extends State<LiveRoomPage>
width: 34,
height: 34,
type: 'avatar',
src: _liveRoomController.roomInfoH5.value
.anchorInfo!.baseInfo!.face,
src: _liveRoomController
.roomInfoH5.value.anchorInfo!.baseInfo!.face,
),
),
const SizedBox(width: 10),
@@ -267,13 +313,12 @@ class _LiveRoomPageState extends State<LiveRoomPage>
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_liveRoomController.roomInfoH5.value
.anchorInfo!.baseInfo!.uname!,
_liveRoomController
.roomInfoH5.value.anchorInfo!.baseInfo!.uname!,
style: const TextStyle(fontSize: 14),
),
const SizedBox(height: 1),
if (_liveRoomController
.roomInfoH5.value.watchedShow !=
if (_liveRoomController.roomInfoH5.value.watchedShow !=
null)
Text(
_liveRoomController.roomInfoH5.value
@@ -312,17 +357,67 @@ class _LiveRoomPageState extends State<LiveRoomPage>
}
},
),
),
);
Widget get _buildBodyH {
double videoWidth =
max(context.height / context.width * 1.04, 0.58) * context.width;
return Expanded(
child: Row(
children: [
Obx(
() => PopScope(
canPop: plPlayerController.isFullScreen.value != true,
onPopInvokedWithResult: (bool didPop, Object? result) {
if (plPlayerController.isFullScreen.value == true) {
plPlayerController.triggerFullScreen(status: false);
}
},
child: Listener(
onPointerDown: (_) {
_node.unfocus();
},
child: SizedBox(
width: plPlayerController.isFullScreen.value
? Get.size.width
: videoWidth,
height: plPlayerController.isFullScreen.value
? Get.size.height
: Get.size.width * 9 / 16,
child: MediaQuery.removePadding(
removeRight: true,
context: context,
child: videoPlayerPanel(Colors.transparent),
),
),
),
),
),
Expanded(
child: Scaffold(
backgroundColor: Colors.transparent,
body: SafeArea(
left: false,
top: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _buildBottomWidget,
),
),
),
),
],
),
);
}
List<Widget> get _buildBodyP => [
Obx(
() => PopScope(
canPop: plPlayerController.isFullScreen.value != true,
onPopInvokedWithResult: (bool didPop, Object? result) {
if (plPlayerController.isFullScreen.value == true) {
plPlayerController.triggerFullScreen(status: false);
// if (MediaQuery.of(context).orientation ==
// Orientation.landscape) {
// verticalScreenForTwoSeconds();
// }
}
},
child: Listener(
@@ -331,15 +426,20 @@ class _LiveRoomPageState extends State<LiveRoomPage>
},
child: SizedBox(
width: Get.size.width,
height: MediaQuery.of(context).orientation ==
Orientation.landscape
height: plPlayerController.isFullScreen.value
? Get.size.height
: Get.size.width * 9 / 16,
child: videoPlayerPanel,
child: videoPlayerPanel(),
),
),
),
),
..._buildBottomWidget,
];
final GlobalKey chatKey = GlobalKey();
List<Widget> get _buildBottomWidget => [
Expanded(
child: Listener(
onPointerDown: (_) {
@@ -348,6 +448,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: LiveRoomChat(
key: chatKey,
roomId: _roomId,
liveRoomController: _liveRoomController,
),
@@ -423,31 +524,8 @@ class _LiveRoomPageState extends State<LiveRoomPage>
),
],
),
),
],
),
],
),
);
}
@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_updateFontSize();
});
if (Platform.isAndroid) {
return PiPSwitcher(
getChildWhenDisabled: () => childWhenDisabled,
getChildWhenEnabled: () => videoPlayerPanel,
floating: floating,
);
} else {
return childWhenDisabled;
}
}
Color get _color => Color(0xFFEEEEEE);
)
];
void _onSendMsg(msg) async {
if (!_isLogin) {
@@ -458,6 +536,9 @@ class _LiveRoomPageState extends State<LiveRoomPage>
roomId: _liveRoomController.roomId, msg: msg);
if (res['status']) {
_ctr.clear();
if (mounted) {
FocusScope.of(context).unfocus();
}
SmartDialog.showToast('发送成功');
} else {
SmartDialog.showToast(res['msg']);

View File

@@ -34,7 +34,7 @@ class ReplyPage extends CommonPublishPage {
}
class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
RxBool _syncToDynamic = false.obs;
final RxBool _syncToDynamic = false.obs;
@override
Widget build(BuildContext context) {

View File

@@ -53,6 +53,7 @@ class PLVideoPlayer extends StatefulWidget {
this.customWidgets,
this.showEpisodes,
this.showViewPoints,
this.fill,
super.key,
});
@@ -68,6 +69,7 @@ class PLVideoPlayer extends StatefulWidget {
final List<Widget>? customWidgets;
final Function? showEpisodes;
final VoidCallback? showViewPoints;
final Color? fill;
@override
State<PLVideoPlayer> createState() => _PLVideoPlayerState();
@@ -844,6 +846,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
flipX: plPlayerController.flipX.value,
flipY: plPlayerController.flipY.value,
child: Video(
fill: widget.fill ?? Colors.black,
key: plPlayerController.key,
controller: videoController,
controls: NoVideoControls,