From 0d977da75bd36173a62d33437f2f7983ab34c297 Mon Sep 17 00:00:00 2001 From: Zhou Weidong <502333560@qq.com> Date: Mon, 19 Oct 2026 17:14:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(player):=20=E4=BF=9D=E6=8C=81=E6=B8=85?= =?UTF-8?q?=E5=B1=8F=E5=B9=B6=E5=B8=B8=E9=A9=BB=E4=B8=AD=E5=BF=83=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/player/player_view.dart | 39 +++-- test/player/player_fullscreen_test.dart | 183 ++++++++++++++++++++---- 2 files changed, 171 insertions(+), 51 deletions(-) diff --git a/lib/pages/player/player_view.dart b/lib/pages/player/player_view.dart index 93d2f84..c45ff8c 100644 --- a/lib/pages/player/player_view.dart +++ b/lib/pages/player/player_view.dart @@ -128,9 +128,6 @@ class _PlayerPageState extends State with WidgetsBindingObserver { itemCount: indices.length, onPageChanged: (position) { final index = indices[position]; - if (widget.homeMode && !_feedChromeVisible) { - setState(() => _feedChromeVisible = true); - } widget.onDramaChanged?.call(logic.queue.entryAt(index).drama); unawaited(logic.selectEpisode(index)); }, @@ -221,18 +218,6 @@ class _PlayerPageState extends State with WidgetsBindingObserver { logic.session.setUserWantsPlay(!logic.session.userWantsPlay), ), ), - if (widget.homeMode && - _feedChromeVisible && - !logic.chromeHidden && - selected && - !logic.session.userWantsPlay) - Center( - child: PlayerCenterToggle( - key: const Key('home-feed-center-play'), - playing: false, - onTap: () => logic.session.setUserWantsPlay(true), - ), - ), // 票据三态之一:起播前正在向后端要签名地址 if (selected && logic.ticketLoading) const Center( @@ -466,6 +451,15 @@ class _PlayerPageState extends State with WidgetsBindingObserver { ), ), ), + if (widget.homeMode && !logic.chromeHidden && selected) + Center( + child: PlayerCenterToggle( + key: const Key('home-feed-center-play'), + playing: logic.session.userWantsPlay, + onTap: () => + logic.session.setUserWantsPlay(!logic.session.userWantsPlay), + ), + ), ], ); } @@ -669,14 +663,6 @@ class _PlaybackOverlayState extends State<_PlaybackOverlay> { Expanded( child: Stack( children: [ - if (!widget.playing) - Center( - child: PlayerCenterToggle( - key: const Key('player-play-toggle'), - playing: false, - onTap: widget.onTogglePlay, - ), - ), const Positioned( right: 10, bottom: 14, @@ -787,6 +773,13 @@ class _PlaybackOverlayState extends State<_PlaybackOverlay> { onPressed: () => setState(() => _controlsVisible = true), ), ), + Center( + child: PlayerCenterToggle( + key: const Key('player-play-toggle'), + playing: widget.playing, + onTap: widget.onTogglePlay, + ), + ), ], ), ); diff --git a/test/player/player_fullscreen_test.dart b/test/player/player_fullscreen_test.dart index b946d8a..7b46bdd 100644 --- a/test/player/player_fullscreen_test.dart +++ b/test/player/player_fullscreen_test.dart @@ -69,9 +69,7 @@ void main() { expect(tester.takeException(), isNull); }); - testWidgets('should_show_play_toggle_only_when_playback_is_paused', ( - tester, - ) async { + testWidgets('should_keep_center_toggle_in_both_play_states', (tester) async { await _pumpApp(tester); await tester.binding.handlePopRoute(); await tester.pumpAndSettle(); @@ -82,18 +80,51 @@ void main() { await tester.tap(find.byKey(const Key('detail-cta'))); await tester.pumpAndSettle(); - expect(find.byKey(const Key('player-play-toggle')), findsNothing); - - await tester.tap(find.byKey(const Key('player-video-tap'))); - await tester.pump(); - expect(find.byKey(const Key('player-play-toggle')), findsOneWidget); - expect(find.byKey(const Key('player-controls-top')), findsOneWidget); - expect(find.byKey(const Key('player-controls-bottom')), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('player-play-toggle')), + ) + .playing, + isTrue, + ); await tester.tap(find.byKey(const Key('player-play-toggle'))); await tester.pump(); - expect(find.byKey(const Key('player-play-toggle')), findsNothing); + expect( + tester + .widget( + find.byKey(const Key('player-play-toggle')), + ) + .playing, + isFalse, + ); + expect( + find.descendant( + of: find.byKey(const Key('player-play-toggle')), + matching: find.byIcon(Icons.play_arrow_rounded), + ), + findsOneWidget, + ); + + await tester.tap(find.byKey(const Key('player-play-toggle'))); + await tester.pump(); + expect( + tester + .widget( + find.byKey(const Key('player-play-toggle')), + ) + .playing, + isTrue, + ); + expect( + find.descendant( + of: find.byKey(const Key('player-play-toggle')), + matching: find.byIcon(Icons.pause_rounded), + ), + findsOneWidget, + ); }); testWidgets('should_keep_controls_visible_until_clear_screen_is_tapped', ( @@ -111,11 +142,19 @@ void main() { expect(find.byKey(const Key('player-controls-top')), findsOneWidget); expect(find.byKey(const Key('player-controls-bottom')), findsOneWidget); - expect(find.byType(PlayerCenterToggle), findsNothing); + expect(find.byType(PlayerCenterToggle), findsOneWidget); - await tester.tap(find.byKey(const Key('player-video-tap'))); + await tester.tapAt(const Offset(80, 300)); await tester.pump(); expect(find.byType(PlayerCenterToggle), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('player-play-toggle')), + ) + .playing, + isFalse, + ); await tester.pump(const Duration(seconds: 5)); await tester.pump(); @@ -129,7 +168,15 @@ void main() { expect(find.byKey(const Key('player-controls-top')), findsNothing); expect(find.byKey(const Key('player-controls-bottom')), findsNothing); - expect(find.byType(PlayerCenterToggle), findsNothing); + expect(find.byType(PlayerCenterToggle), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('player-play-toggle')), + ) + .playing, + isFalse, + ); expect(find.byKey(const Key('player-video-tap')), findsOneWidget); expect(find.byKey(const Key('player-exit-clear-screen')), findsOneWidget); expect( @@ -137,21 +184,45 @@ void main() { const Size(36, 36), ); - await tester.tap(find.byKey(const Key('player-video-tap'))); + await tester.tapAt(const Offset(80, 300)); await tester.pump(); expect(find.byKey(const Key('player-controls-top')), findsNothing); expect(find.byKey(const Key('player-exit-clear-screen')), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('player-play-toggle')), + ) + .playing, + isTrue, + ); - await tester.tap(find.byKey(const Key('player-video-tap'))); + await tester.tapAt(const Offset(80, 300)); await tester.pump(); expect(find.byKey(const Key('player-controls-top')), findsNothing); expect(find.byKey(const Key('player-exit-clear-screen')), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('player-play-toggle')), + ) + .playing, + isFalse, + ); await tester.tap(find.byKey(const Key('player-exit-clear-screen'))); await tester.pump(); expect(find.byKey(const Key('player-controls-top')), findsOneWidget); expect(find.byKey(const Key('player-controls-bottom')), findsOneWidget); expect(find.byType(PlayerCenterToggle), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('player-play-toggle')), + ) + .playing, + isFalse, + ); expect(find.byKey(const Key('player-exit-clear-screen')), findsNothing); }); @@ -181,6 +252,15 @@ void main() { expect(find.byKey(const Key('home-feed-title')), findsOneWidget); expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget); expect(find.byKey(const Key('home-feed-scrim')), findsOneWidget); + expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('home-feed-center-play')), + ) + .playing, + isTrue, + ); await tester.tap(find.byKey(const Key('home-feed-clear-screen'))); await tester.pump(); @@ -197,6 +277,7 @@ void main() { tester.getSize(find.byKey(const Key('home-feed-exit-clear-screen'))), const Size(36, 36), ); + expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); expect( find.ancestor( of: find.byKey(const Key('home-feed-exit-clear-screen')), @@ -211,21 +292,37 @@ void main() { greaterThanOrEqualTo(8), ); - await tester.tap(find.byKey(const Key('home-feed-video-tap'))); + await tester.tapAt(const Offset(80, 300)); await tester.pump(); expect(find.byKey(const Key('home-feed-title')), findsNothing); expect( find.byKey(const Key('home-feed-exit-clear-screen')), findsOneWidget, ); + expect( + tester + .widget( + find.byKey(const Key('home-feed-center-play')), + ) + .playing, + isFalse, + ); - await tester.tap(find.byKey(const Key('home-feed-video-tap'))); + await tester.tapAt(const Offset(80, 300)); await tester.pump(); expect(find.byKey(const Key('home-feed-title')), findsNothing); expect( find.byKey(const Key('home-feed-exit-clear-screen')), findsOneWidget, ); + expect( + tester + .widget( + find.byKey(const Key('home-feed-center-play')), + ) + .playing, + isTrue, + ); await tester.tap(find.byKey(const Key('home-feed-exit-clear-screen'))); await tester.pump(); @@ -234,25 +331,51 @@ void main() { expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget); expect(find.byKey(const Key('home-feed-scrim')), findsOneWidget); expect(find.byKey(const Key('home-feed-exit-clear-screen')), findsNothing); - expect(find.byKey(const Key('home-feed-center-play')), findsNothing); + expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); }); - testWidgets('should_show_home_play_toggle_only_when_paused', (tester) async { + testWidgets('should_keep_home_center_toggle_in_both_play_states', ( + tester, + ) async { await _pumpApp(tester); await tester.tap(find.byKey(const Key('tab-home'))); await tester.pumpAndSettle(); - expect(find.byKey(const Key('home-feed-center-play')), findsNothing); - await tester.tap(find.byKey(const Key('home-feed-video-toggle'))); + expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('home-feed-center-play')), + ) + .playing, + isTrue, + ); + await tester.tapAt(const Offset(80, 300)); await tester.pump(); expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('home-feed-center-play')), + ) + .playing, + isFalse, + ); await tester.tap(find.byKey(const Key('home-feed-center-play'))); await tester.pump(); - expect(find.byKey(const Key('home-feed-center-play')), findsNothing); + expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('home-feed-center-play')), + ) + .playing, + isTrue, + ); }); - testWidgets('should_reset_home_chrome_when_swiping_to_next_page', ( + testWidgets('should_keep_home_clear_state_when_swiping_to_next_page', ( tester, ) async { await _pumpApp(tester); @@ -265,9 +388,13 @@ void main() { await tester.drag(find.byType(PageView), const Offset(0, -550)); await tester.pumpAndSettle(); - expect(find.byKey(const Key('home-feed-title')), findsOneWidget); - expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget); - expect(find.byKey(const Key('home-feed-exit-clear-screen')), findsNothing); + expect(find.byKey(const Key('home-feed-title')), findsNothing); + expect(find.byKey(const Key('home-feed-info-card')), findsNothing); + expect( + find.byKey(const Key('home-feed-exit-clear-screen')), + findsOneWidget, + ); + expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); }); } @@ -278,7 +405,7 @@ void _expectFullscreenOverlay(WidgetTester tester) { for (final key in const [Key('player-back'), Key('player-more')]) { expect(tester.getSize(find.byKey(key)), const Size(36, 36)); } - expect(find.byKey(const Key('player-play-toggle')), findsNothing); + expect(find.byKey(const Key('player-play-toggle')), findsOneWidget); expect(find.byKey(const Key('player-episodes')), findsOneWidget); expect(find.byKey(const Key('player-comments')), findsOneWidget); expect(find.byKey(const Key('player-next')), findsOneWidget);