From 43d866bfe1e46407dbcb7a0eb5b55c71d85c9a30 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 9 Nov 2024 23:22:19 +0800 Subject: [PATCH] fix: season currentIndex --- lib/common/pages_bottom_sheet.dart | 7 +++++- lib/models/video_detail_res.dart | 18 ++++++++++++++ .../introduction/widgets/season_panel.dart | 24 ++++++++++++++++--- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/lib/common/pages_bottom_sheet.dart b/lib/common/pages_bottom_sheet.dart index 85f7d33b..3b7bd8b7 100644 --- a/lib/common/pages_bottom_sheet.dart +++ b/lib/common/pages_bottom_sheet.dart @@ -21,6 +21,7 @@ class EpisodeBottomSheet { bool isFullScreen = false; final UgcSeason? ugcSeason; final int? currentEpisodeIndex; + final int? currentIndex; EpisodeBottomSheet({ required this.episodes, @@ -32,6 +33,7 @@ class EpisodeBottomSheet { this.isFullScreen = false, this.ugcSeason, this.currentEpisodeIndex, + this.currentIndex, }); Widget buildShowContent() { @@ -45,6 +47,7 @@ class EpisodeBottomSheet { isFullScreen: isFullScreen, ugcSeason: ugcSeason, currentEpisodeIndex: currentEpisodeIndex, + currentIndex: currentIndex, ); } @@ -71,6 +74,7 @@ class PagesBottomSheet extends StatefulWidget { this.isFullScreen = false, this.ugcSeason, this.currentEpisodeIndex, + this.currentIndex, }); final List episodes; @@ -82,6 +86,7 @@ class PagesBottomSheet extends StatefulWidget { final bool isFullScreen; final UgcSeason? ugcSeason; final int? currentEpisodeIndex; + final int? currentIndex; @override State createState() => _PagesBottomSheetState(); @@ -100,7 +105,7 @@ class _PagesBottomSheetState extends State @override void initState() { super.initState(); - currentIndex = + currentIndex = widget.currentIndex ?? widget.episodes.indexWhere((dynamic e) => e.cid == widget.currentCid); _scrollToInit(); _scrollPositionInit(); diff --git a/lib/models/video_detail_res.dart b/lib/models/video_detail_res.dart index 3401d809..ad52a840 100644 --- a/lib/models/video_detail_res.dart +++ b/lib/models/video_detail_res.dart @@ -641,6 +641,7 @@ class EpisodeItem { this.page, this.bvid, this.cover, + this.pages, }); int? seasonId; int? sectionId; @@ -655,6 +656,7 @@ class EpisodeItem { int? pubdate; int? duration; Stat? stat; + List? pages; EpisodeItem.fromJson(Map json) { seasonId = json['season_id']; @@ -670,6 +672,7 @@ class EpisodeItem { pubdate = json['arc']['pubdate']; duration = json['arc']['duration']; stat = Stat.fromJson(json['arc']['stat']); + pages = json['pages'].map((e) => Page.fromJson(e)).toList(); } } @@ -712,3 +715,18 @@ class Vip { status = json['status']; } } + +class Page { + Page({ + this.cid, + this.page, + }); + + int? cid; + int? page; + + Page.fromJson(Map json) { + cid = json['cid']; + page = json['page']; + } +} diff --git a/lib/pages/video/detail/introduction/widgets/season_panel.dart b/lib/pages/video/detail/introduction/widgets/season_panel.dart index 9d9f33d8..e5a9ea84 100644 --- a/lib/pages/video/detail/introduction/widgets/season_panel.dart +++ b/lib/pages/video/detail/introduction/widgets/season_panel.dart @@ -33,7 +33,7 @@ class _SeasonPanelState extends State { final String heroTag = Get.arguments['heroTag']; late VideoDetailController _videoDetailController; late PersistentBottomSheetController? _bottomSheetController; - int currentEpisodeIndex = 0; + int currentEpisodeIndex = -1; @override void initState() { @@ -55,10 +55,10 @@ class _SeasonPanelState extends State { } /// 取对应 season_id 的 episodes - currentIndex.value = episodes.indexWhere((EpisodeItem e) => e.cid == cid); + getCurrentIndex(); _videoDetailController.cid.listen((int p0) { cid = p0; - currentIndex.value = episodes.indexWhere((EpisodeItem e) => e.cid == cid); + getCurrentIndex(); }); } @@ -73,6 +73,23 @@ class _SeasonPanelState extends State { _bottomSheetController?.close(); } + // 获取currentIndex + void getCurrentIndex() { + currentIndex.value = episodes.indexWhere((EpisodeItem e) => e.cid == cid); + final List sections = widget.ugcSeason.sections!; + if (sections.length == 1 && sections.first.type == 1) { + final List episodesList = sections.first.episodes!; + for (int i = 0; i < episodesList.length; i++) { + for (int j = 0; j < episodesList[i].pages!.length; j++) { + if (episodesList[i].pages![j].cid == cid) { + currentIndex.value = i; + continue; + } + } + } + } + } + Widget buildEpisodeListItem( EpisodeItem episode, int index, @@ -126,6 +143,7 @@ class _SeasonPanelState extends State { dataType: VideoEpidoesType.videoEpisode, ugcSeason: widget.ugcSeason, currentEpisodeIndex: currentEpisodeIndex, + currentIndex: currentIndex.value, ).show(context); }, child: Padding(