From 71e317f4ab4485a5f5d2231262e0a57e08942984 Mon Sep 17 00:00:00 2001 From: Zhou Weidong <502333560@qq.com> Date: Mon, 19 Oct 2026 17:20:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(player):=20=E4=B8=AD=E5=BF=83=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E4=BB=85=E6=9A=82=E5=81=9C=E6=97=B6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/player/player_view.dart | 20 +++--- test/player/player_fullscreen_test.dart | 92 +++++-------------------- 2 files changed, 29 insertions(+), 83 deletions(-) diff --git a/lib/pages/player/player_view.dart b/lib/pages/player/player_view.dart index c45ff8c..f71462b 100644 --- a/lib/pages/player/player_view.dart +++ b/lib/pages/player/player_view.dart @@ -451,11 +451,14 @@ class _PlayerPageState extends State with WidgetsBindingObserver { ), ), ), - if (widget.homeMode && !logic.chromeHidden && selected) + if (widget.homeMode && + !logic.chromeHidden && + selected && + !logic.session.userWantsPlay) Center( child: PlayerCenterToggle( key: const Key('home-feed-center-play'), - playing: logic.session.userWantsPlay, + playing: false, onTap: () => logic.session.setUserWantsPlay(!logic.session.userWantsPlay), ), @@ -773,13 +776,14 @@ class _PlaybackOverlayState extends State<_PlaybackOverlay> { onPressed: () => setState(() => _controlsVisible = true), ), ), - Center( - child: PlayerCenterToggle( - key: const Key('player-play-toggle'), - playing: widget.playing, - onTap: widget.onTogglePlay, + if (!widget.playing) + Center( + child: PlayerCenterToggle( + key: const Key('player-play-toggle'), + playing: false, + onTap: widget.onTogglePlay, + ), ), - ), ], ), ); diff --git a/test/player/player_fullscreen_test.dart b/test/player/player_fullscreen_test.dart index 7b46bdd..46737d5 100644 --- a/test/player/player_fullscreen_test.dart +++ b/test/player/player_fullscreen_test.dart @@ -69,7 +69,7 @@ void main() { expect(tester.takeException(), isNull); }); - testWidgets('should_keep_center_toggle_in_both_play_states', (tester) async { + testWidgets('should_show_center_toggle_only_when_paused', (tester) async { await _pumpApp(tester); await tester.binding.handlePopRoute(); await tester.pumpAndSettle(); @@ -80,18 +80,11 @@ void main() { await tester.tap(find.byKey(const Key('detail-cta'))); await tester.pumpAndSettle(); - expect(find.byKey(const Key('player-play-toggle')), findsOneWidget); - expect( - tester - .widget( - find.byKey(const Key('player-play-toggle')), - ) - .playing, - isTrue, - ); + expect(find.byKey(const Key('player-play-toggle')), findsNothing); - await tester.tap(find.byKey(const Key('player-play-toggle'))); + await tester.tapAt(const Offset(80, 300)); await tester.pump(); + expect(find.byKey(const Key('player-play-toggle')), findsOneWidget); expect( tester .widget( @@ -110,21 +103,7 @@ void main() { 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, - ); + expect(find.byKey(const Key('player-play-toggle')), findsNothing); }); testWidgets('should_keep_controls_visible_until_clear_screen_is_tapped', ( @@ -142,7 +121,7 @@ void main() { expect(find.byKey(const Key('player-controls-top')), findsOneWidget); expect(find.byKey(const Key('player-controls-bottom')), findsOneWidget); - expect(find.byType(PlayerCenterToggle), findsOneWidget); + expect(find.byType(PlayerCenterToggle), findsNothing); await tester.tapAt(const Offset(80, 300)); await tester.pump(); @@ -188,14 +167,7 @@ void main() { 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, - ); + expect(find.byType(PlayerCenterToggle), findsNothing); await tester.tapAt(const Offset(80, 300)); await tester.pump(); @@ -252,15 +224,7 @@ 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, - ); + expect(find.byKey(const Key('home-feed-center-play')), findsNothing); await tester.tap(find.byKey(const Key('home-feed-clear-screen'))); await tester.pump(); @@ -277,7 +241,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.byKey(const Key('home-feed-center-play')), findsNothing); expect( find.ancestor( of: find.byKey(const Key('home-feed-exit-clear-screen')), @@ -299,6 +263,7 @@ void main() { find.byKey(const Key('home-feed-exit-clear-screen')), findsOneWidget, ); + expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); expect( tester .widget( @@ -315,14 +280,7 @@ void main() { find.byKey(const Key('home-feed-exit-clear-screen')), findsOneWidget, ); - expect( - tester - .widget( - find.byKey(const Key('home-feed-center-play')), - ) - .playing, - isTrue, - ); + expect(find.byKey(const Key('home-feed-center-play')), findsNothing); await tester.tap(find.byKey(const Key('home-feed-exit-clear-screen'))); await tester.pump(); @@ -331,25 +289,17 @@ 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')), findsOneWidget); + expect(find.byKey(const Key('home-feed-center-play')), findsNothing); }); - testWidgets('should_keep_home_center_toggle_in_both_play_states', ( + testWidgets('should_show_home_center_toggle_only_when_paused', ( 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')), findsOneWidget); - expect( - tester - .widget( - find.byKey(const Key('home-feed-center-play')), - ) - .playing, - isTrue, - ); + expect(find.byKey(const Key('home-feed-center-play')), findsNothing); await tester.tapAt(const Offset(80, 300)); await tester.pump(); expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); @@ -364,15 +314,7 @@ void main() { await tester.tap(find.byKey(const Key('home-feed-center-play'))); 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, - isTrue, - ); + expect(find.byKey(const Key('home-feed-center-play')), findsNothing); }); testWidgets('should_keep_home_clear_state_when_swiping_to_next_page', ( @@ -394,7 +336,7 @@ void main() { find.byKey(const Key('home-feed-exit-clear-screen')), findsOneWidget, ); - expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); + expect(find.byKey(const Key('home-feed-center-play')), findsNothing); }); } @@ -405,7 +347,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')), findsOneWidget); + expect(find.byKey(const Key('player-play-toggle')), findsNothing); expect(find.byKey(const Key('player-episodes')), findsOneWidget); expect(find.byKey(const Key('player-comments')), findsOneWidget); expect(find.byKey(const Key('player-next')), findsOneWidget);