Skip to content

Commit

Permalink
fix: 横竖屏适配标题滚动显示,图标调整,监听器加取消
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Feb 26, 2024
1 parent fe21d55 commit 7cadf46
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/pages/history/widgets/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ class VideoContent extends StatelessWidget {
maxLines: videoItem.videos > 1 ? 1 : 2,
overflow: TextOverflow.ellipsis,
),
if (videoItem.showTitle != null) ...[
if (videoItem.isFullScreen != null) ...[
const SizedBox(height: 2),
Text(
videoItem.showTitle,
videoItem.isFullScreen,
textAlign: TextAlign.start,
style: TextStyle(
fontSize: Theme.of(context).textTheme.labelMedium!.fontSize,
Expand Down
67 changes: 45 additions & 22 deletions lib/pages/video/detail/widgets/header_control.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'dart:math';

Expand All @@ -20,6 +21,7 @@ import 'package:PiliPalaX/http/danmaku.dart';
import 'package:PiliPalaX/services/shutdown_timer_service.dart';
import '../../../../models/video_detail_res.dart';
import '../introduction/index.dart';
import 'package:marquee/marquee.dart';

class HeaderControl extends StatefulWidget implements PreferredSizeWidget {
const HeaderControl({
Expand Down Expand Up @@ -49,38 +51,41 @@ class _HeaderControlState extends State<HeaderControl> {
final Box<dynamic> videoStorage = GStrorage.video;
late List<double> speedsList;
double buttonSpace = 8;
bool showTitle = false;
bool isFullScreen = false;
late String heroTag;
late VideoIntroController videoIntroController;
late VideoDetailData videoDetail;
late StreamSubscription<bool> fullScreenStatusListener;
late bool horizontalScreen;

@override
void initState() {
super.initState();
videoInfo = widget.videoDetailCtr!.data;
speedsList = widget.controller!.speedsList;
fullScreenStatusListener();
listenFullScreenStatus();
heroTag = Get.arguments['heroTag'];
videoIntroController = Get.put(VideoIntroController(), tag: heroTag);
horizontalScreen =
setting.get(SettingBoxKey.horizontalScreen, defaultValue: false);
}

void fullScreenStatusListener() {
widget.videoDetailCtr!.plPlayerController.isFullScreen
.listen((bool isFullScreen) {
if (isFullScreen) {
showTitle = true;
} else {
showTitle = false;
}
void listenFullScreenStatus() {
fullScreenStatusListener = widget
.videoDetailCtr!.plPlayerController.isFullScreen
.listen((bool status) {
isFullScreen = status;
setState(() {});
});
}

@override
void dispose() {
widget.floating?.dispose();
fullScreenStatusListener.cancel();
super.dispose();
}

/// 设置面板
void showSettingSheet() {
showModalBottomSheet(
Expand Down Expand Up @@ -1085,6 +1090,7 @@ class _HeaderControlState extends State<HeaderControl> {
titleSpacing: 14,
title: Row(
children: [
// SizedBox(width: MediaQuery.of(context).padding.left,),
ComBtn(
icon: const Icon(
FontAwesomeIcons.arrowLeft,
Expand All @@ -1098,8 +1104,7 @@ class _HeaderControlState extends State<HeaderControl> {
<void>{
if (MediaQuery.of(context).orientation ==
Orientation.landscape &&
!setting.get(SettingBoxKey.horizontalScreen,
defaultValue: false))
!horizontalScreen)
{
verticalScreen(),
},
Expand All @@ -1108,18 +1113,34 @@ class _HeaderControlState extends State<HeaderControl> {
},
),
SizedBox(width: buttonSpace),
if (showTitle && isLandscape) ...[
if (isFullScreen ||
(!isFullScreen && isLandscape && !horizontalScreen)) ...[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ConstrainedBox(
constraints: BoxConstraints(maxWidth: 200),
child: Text(
videoIntroController.videoDetail.value.title!,
constraints: BoxConstraints(
maxWidth: isLandscape ? 400 : 100, maxHeight: 20),
child: Marquee(
text: videoIntroController.videoDetail.value.title!,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
),
scrollAxis: Axis.horizontal,
crossAxisAlignment: CrossAxisAlignment.start,
blankSpace: 200,
velocity: 40,
startAfter: const Duration(seconds: 1),
showFadingOnlyWhenScrolling: true,
fadingEdgeStartFraction: 0.1,
fadingEdgeEndFraction: 0.1,
numberOfRounds: 1,
startPadding: 0,
accelerationDuration: const Duration(seconds: 1),
accelerationCurve: Curves.linear,
decelerationDuration: const Duration(milliseconds: 500),
decelerationCurve: Curves.easeOut,
),
),
if (videoIntroController.isShowOnlineTotal)
Expand Down Expand Up @@ -1159,19 +1180,21 @@ class _HeaderControlState extends State<HeaderControl> {
// fuc: () => _.screenshot(),
// ),
SizedBox(
width: 56,
width: 34,
height: 34,
child: TextButton(
child: IconButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
onPressed: () => showShootDanmakuSheet(),
child: const Text(
'发弹幕',
style: textStyle,
icon: const Icon(
Icons.add_card_outlined,
size: 19,
color: Colors.white,
),
),
),
SizedBox(width: buttonSpace),
SizedBox(
width: 34,
height: 34,
Expand Down Expand Up @@ -1225,7 +1248,7 @@ class _HeaderControlState extends State<HeaderControl> {
],
Obx(
() => SizedBox(
width: 45,
width: 34,
height: 34,
child: TextButton(
style: ButtonStyle(
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,14 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "6.2.1"
fading_edge_scrollview:
dependency: transitive
description:
name: fading_edge_scrollview
sha256: c25c2231652ce774cc31824d0112f11f653881f43d7f5302c05af11942052031
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.0.0"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -830,6 +838,14 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "6.0.1"
marquee:
dependency: "direct main"
description:
name: marquee
sha256: "4b5243d2804373bdc25fc93d42c3b402d6ec1f4ee8d0bb72276edd04ae7addb8"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.2.3"
matcher:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ dependencies:
path: 1.8.3
#瀑布流
waterfall_flow: ^3.0.3
marquee: ^2.2.3

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 7cadf46

Please sign in to comment.