diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index 2671f4d8..eafedd08 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -85,15 +85,14 @@ class VideoIntroController extends GetxController { } // 获取视频简介&分p - Future queryVideoIntro({cover}) async { + Future queryVideoIntro({String? cover, String? type, int? cid}) async { var result = await VideoHttp.videoIntro(bvid: bvid); if (result['status']) { videoDetail.value = result['data']!; ugcSeason = result['data']!.ugcSeason; pages.value = result['data']!.pages!; - lastPlayCid.value = videoDetail.value.cid!; - if (pages.isNotEmpty) { - lastPlayCid.value = pages.first.cid!; + if (type == null) { + lastPlayCid.value = cid ?? videoDetail.value.cid!; } final VideoDetailController videoDetailCtr = Get.find(tag: heroTag); @@ -473,7 +472,8 @@ class VideoIntroController extends GetxController { videoReplyCtr.queryReplyList(type: 'init'); } catch (_) {} this.bvid = bvid; - await queryVideoIntro(cover: cover); + // 点击切换时,优先取当前cid + await queryVideoIntro(cover: cover, cid: cid); } void startTimer() { diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index a02ed530..9ceb35e0 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -57,7 +57,7 @@ class _VideoIntroPanelState extends State heroTag = Get.arguments['heroTag']; videoIntroController = Get.put(VideoIntroController(bvid: widget.bvid), tag: heroTag); - _futureBuilderFuture = videoIntroController.queryVideoIntro(); + _futureBuilderFuture = videoIntroController.queryVideoIntro(type: 'init'); videoIntroController.videoDetail.listen((value) { videoDetail = value; }); diff --git a/lib/pages/video/detail/introduction/widgets/season_panel.dart b/lib/pages/video/detail/introduction/widgets/season_panel.dart index e5a9ea84..291f1622 100644 --- a/lib/pages/video/detail/introduction/widgets/season_panel.dart +++ b/lib/pages/video/detail/introduction/widgets/season_panel.dart @@ -27,7 +27,7 @@ class SeasonPanel extends StatefulWidget { } class _SeasonPanelState extends State { - late List episodes; + List? episodes; late int cid; late RxInt currentIndex = (-1).obs; final String heroTag = Get.arguments['heroTag']; @@ -75,7 +75,10 @@ class _SeasonPanelState extends State { // 获取currentIndex void getCurrentIndex() { - currentIndex.value = episodes.indexWhere((EpisodeItem e) => e.cid == cid); + if (episodes != null) { + 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!; @@ -83,6 +86,7 @@ class _SeasonPanelState extends State { for (int j = 0; j < episodesList[i].pages!.length; j++) { if (episodesList[i].pages![j].cid == cid) { currentIndex.value = i; + episodes = episodesList; continue; } } @@ -137,7 +141,7 @@ class _SeasonPanelState extends State { widget.videoIntroCtr.bottomSheetController = _bottomSheetController = EpisodeBottomSheet( currentCid: cid, - episodes: episodes, + episodes: episodes!, changeFucCall: changeFucCall, sheetHeight: widget.sheetHeight, dataType: VideoEpidoesType.videoEpisode, @@ -165,7 +169,7 @@ class _SeasonPanelState extends State { ), const SizedBox(width: 10), Obx(() => Text( - '${currentIndex.value + 1}/${episodes.length}', + '${currentIndex.value + 1}/${episodes!.length}', style: Theme.of(context).textTheme.labelMedium, )), const SizedBox(width: 6),