fix: video tabbar

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-12-25 17:19:31 +08:00
parent f6406f47a6
commit 234017cc8a

View File

@@ -1189,19 +1189,22 @@ class _VideoDetailPageState extends State<VideoDetailPage>
bool showIntro = true, bool showIntro = true,
bool showReply = true, bool showReply = true,
}) { }) {
int length = (showIntro ? 1 : 0) + List<String> tabs = [
(showReply ? 1 : 0) + if (showIntro) introText,
(_shouldShowSeasonPanel ? 1 : 0); if (showReply) '评论',
if (videoDetailController.tabCtr.length != length) { if (_shouldShowSeasonPanel) '播放列表',
videoDetailController.tabCtr = TabController(length: length, vsync: this); ];
if (videoDetailController.tabCtr.length != tabs.length) {
videoDetailController.tabCtr =
TabController(length: tabs.length, vsync: this);
} }
Widget tabbar() => TabBar( Widget tabbar() => TabBar(
labelColor: needIndicator.not || length == 1 labelColor: needIndicator.not || tabs.length == 1
? Theme.of(context).colorScheme.onSurface ? Theme.of(context).colorScheme.onSurface
: null, : null,
indicatorColor: indicatorColor:
needIndicator.not || length == 1 ? Colors.transparent : null, needIndicator.not || tabs.length == 1 ? Colors.transparent : null,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
controller: videoDetailController.tabCtr, controller: videoDetailController.tabCtr,
labelStyle: const TextStyle(fontSize: 13), labelStyle: const TextStyle(fontSize: 13),
@@ -1210,32 +1213,30 @@ class _VideoDetailPageState extends State<VideoDetailPage>
dividerColor: Colors.transparent, dividerColor: Colors.transparent,
onTap: (value) { onTap: (value) {
void animToTop() { void animToTop() {
if (value == 0) { String text = tabs[value];
if (showIntro) { if (text == '简介' || text == '相关视频') {
_introController.animToTop(); _introController.animToTop();
} else if (showReply) { } else if (text.startsWith('评论')) {
_videoReplyController.animateToTop();
}
} else {
_videoReplyController.animateToTop(); _videoReplyController.animateToTop();
} }
} }
if (needIndicator.not || length == 1) { if (needIndicator.not || tabs.length == 1) {
animToTop(); animToTop();
} else if (videoDetailController.tabCtr.indexIsChanging.not) { } else if (videoDetailController.tabCtr.indexIsChanging.not) {
animToTop(); animToTop();
} }
}, },
tabs: [ tabs: tabs.map((text) {
if (showIntro) Tab(text: introText), if (text == '评论') {
if (showReply) return Tab(
Tab(
text: text:
'评论${_videoReplyController.count.value == -1 ? '' : ' ${_videoReplyController.count.value}'}', '评论${_videoReplyController.count.value == -1 ? '' : ' ${_videoReplyController.count.value}'}',
), );
if (_shouldShowSeasonPanel) Tab(text: '播放列表'), } else {
], return Tab(text: text);
}
}).toList(),
); );
return Container( return Container(
@@ -1252,11 +1253,11 @@ class _VideoDetailPageState extends State<VideoDetailPage>
child: Material( child: Material(
child: Row( child: Row(
children: [ children: [
if (length == 0) if (tabs.isEmpty)
const Spacer() const Spacer()
else else
Flexible( Flexible(
flex: length == 3 ? 2 : 1, flex: tabs.length == 3 ? 2 : 1,
child: showReply ? Obx(() => tabbar()) : tabbar(), child: showReply ? Obx(() => tabbar()) : tabbar(),
), ),
Flexible( Flexible(