From 08cb807f39d4983743fda5e8359ef1655cbf9714 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Mon, 11 Nov 2024 23:46:08 +0800 Subject: [PATCH 1/2] fix: history cid --- lib/pages/video/detail/introduction/controller.dart | 10 +++++----- lib/pages/video/detail/introduction/view.dart | 2 +- .../detail/introduction/widgets/season_panel.dart | 12 ++++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) 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), From ea900ffe4eaf3f4ceef1d3b57064b845a5045844 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 24 Nov 2024 22:53:48 +0800 Subject: [PATCH 2/2] opt: jumpTo rebound --- lib/common/pages_bottom_sheet.dart | 64 ++++++++++++++++-------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/lib/common/pages_bottom_sheet.dart b/lib/common/pages_bottom_sheet.dart index dd8c5490..fa6f61c7 100644 --- a/lib/common/pages_bottom_sheet.dart +++ b/lib/common/pages_bottom_sheet.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:pilipala/common/constants.dart'; @@ -98,7 +99,8 @@ class _PagesBottomSheetState extends State with TickerProviderStateMixin { final ScrollController _listScrollController = ScrollController(); late ListObserverController _listObserverController; - final ScrollController _scrollController = ScrollController(); + late GridObserverController _gridObserverController; + final ScrollController _gridScrollController = ScrollController(); late int currentIndex; TabController? tabController; List? _listObserverControllerList; @@ -163,6 +165,9 @@ class _PagesBottomSheetState extends State ); }, ); + } else { + _gridObserverController = + GridObserverController(controller: _gridScrollController); } } @@ -185,18 +190,12 @@ class _PagesBottomSheetState extends State ); } } + } else { + _gridObserverController.initialIndexModel = ObserverIndexPositionModel( + index: currentIndex, + isFixedHeight: false, + ); } - - WidgetsBinding.instance.addPostFrameCallback((_) { - if (widget.dataType != VideoEpidoesType.videoEpisode) { - double itemHeight = (widget.isFullScreen - ? 400 - : Get.size.width - 3 * StyleString.safeSpace) / - 5.2; - double offset = ((currentIndex - 1) / 2).ceil() * itemHeight; - _scrollController.jumpTo(offset); - } - }); } // 获取订阅状态 @@ -236,7 +235,9 @@ class _PagesBottomSheetState extends State void dispose() { try { _listObserverController.controller?.dispose(); + _gridObserverController.controller?.dispose(); _listScrollController.dispose(); + _gridScrollController.dispose(); for (var element in _listObserverControllerList!) { element.controller?.dispose(); } @@ -303,24 +304,27 @@ class _PagesBottomSheetState extends State : Padding( padding: const EdgeInsets.symmetric( horizontal: 12.0), // 设置左右间距为12 - child: GridView.count( - controller: _scrollController, - crossAxisCount: 2, - crossAxisSpacing: StyleString.safeSpace, - childAspectRatio: 2.6, - children: List.generate( - widget.episodes.length, - (index) { - bool isCurrentIndex = currentIndex == index; - return EpisodeGridItem( - episode: widget.episodes[index], - index: index, - isCurrentIndex: isCurrentIndex, - dataType: widget.dataType, - changeFucCall: widget.changeFucCall, - isFullScreen: widget.isFullScreen, - ); - }, + child: GridViewObserver( + controller: _gridObserverController, + child: GridView.count( + controller: _gridScrollController, + crossAxisCount: 2, + crossAxisSpacing: StyleString.safeSpace, + childAspectRatio: 2.6, + children: List.generate( + widget.episodes.length, + (index) { + bool isCurrentIndex = currentIndex == index; + return EpisodeGridItem( + episode: widget.episodes[index], + index: index, + isCurrentIndex: isCurrentIndex, + dataType: widget.dataType, + changeFucCall: widget.changeFucCall, + isFullScreen: widget.isFullScreen, + ); + }, + ), ), ), ),