From 234017cc8a862f0af151c6efd44faf4369fd9f85 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Wed, 25 Dec 2024 17:19:31 +0800 Subject: [PATCH] fix: video tabbar Signed-off-by: bggRGjQaUbCoE --- lib/pages/video/detail/view.dart | 49 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index 6eb8c88f..65c6375b 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -1189,19 +1189,22 @@ class _VideoDetailPageState extends State bool showIntro = true, bool showReply = true, }) { - int length = (showIntro ? 1 : 0) + - (showReply ? 1 : 0) + - (_shouldShowSeasonPanel ? 1 : 0); - if (videoDetailController.tabCtr.length != length) { - videoDetailController.tabCtr = TabController(length: length, vsync: this); + List tabs = [ + if (showIntro) introText, + if (showReply) '评论', + if (_shouldShowSeasonPanel) '播放列表', + ]; + if (videoDetailController.tabCtr.length != tabs.length) { + videoDetailController.tabCtr = + TabController(length: tabs.length, vsync: this); } Widget tabbar() => TabBar( - labelColor: needIndicator.not || length == 1 + labelColor: needIndicator.not || tabs.length == 1 ? Theme.of(context).colorScheme.onSurface : null, indicatorColor: - needIndicator.not || length == 1 ? Colors.transparent : null, + needIndicator.not || tabs.length == 1 ? Colors.transparent : null, padding: EdgeInsets.zero, controller: videoDetailController.tabCtr, labelStyle: const TextStyle(fontSize: 13), @@ -1210,32 +1213,30 @@ class _VideoDetailPageState extends State dividerColor: Colors.transparent, onTap: (value) { void animToTop() { - if (value == 0) { - if (showIntro) { - _introController.animToTop(); - } else if (showReply) { - _videoReplyController.animateToTop(); - } - } else { + String text = tabs[value]; + if (text == '简介' || text == '相关视频') { + _introController.animToTop(); + } else if (text.startsWith('评论')) { _videoReplyController.animateToTop(); } } - if (needIndicator.not || length == 1) { + if (needIndicator.not || tabs.length == 1) { animToTop(); } else if (videoDetailController.tabCtr.indexIsChanging.not) { animToTop(); } }, - tabs: [ - if (showIntro) Tab(text: introText), - if (showReply) - Tab( + tabs: tabs.map((text) { + if (text == '评论') { + return Tab( text: '评论${_videoReplyController.count.value == -1 ? '' : ' ${_videoReplyController.count.value}'}', - ), - if (_shouldShowSeasonPanel) Tab(text: '播放列表'), - ], + ); + } else { + return Tab(text: text); + } + }).toList(), ); return Container( @@ -1252,11 +1253,11 @@ class _VideoDetailPageState extends State child: Material( child: Row( children: [ - if (length == 0) + if (tabs.isEmpty) const Spacer() else Flexible( - flex: length == 3 ? 2 : 1, + flex: tabs.length == 3 ? 2 : 1, child: showReply ? Obx(() => tabbar()) : tabbar(), ), Flexible(