From 0eabb0a763faf95e78d97a3ab83f759112992d97 Mon Sep 17 00:00:00 2001 From: Zhou Weidong <502333560@qq.com> Date: Mon, 19 Oct 2026 16:50:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(player):=20=E4=BB=85=E5=9C=A8=E6=9A=82?= =?UTF-8?q?=E5=81=9C=E6=97=B6=E6=98=BE=E7=A4=BA=E6=92=AD=E6=94=BE=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 | 28 +++++++++++++++++--- test/player/player_fullscreen_test.dart | 35 ++++++++++++++++++++----- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/lib/pages/player/player_view.dart b/lib/pages/player/player_view.dart index 49edc2a..23e9db4 100644 --- a/lib/pages/player/player_view.dart +++ b/lib/pages/player/player_view.dart @@ -208,6 +208,28 @@ class _PlayerPageState extends State with WidgetsBindingObserver { ), ), ), + if (widget.homeMode && _feedChromeVisible && !logic.chromeHidden) + Positioned.fill( + child: GestureDetector( + key: const Key('home-feed-video-toggle'), + behavior: HitTestBehavior.opaque, + onTap: () => 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( @@ -605,7 +627,7 @@ class _PlaybackOverlayState extends State<_PlaybackOverlay> { void _onVideoTap() { if (!_controlsVisible) { setState(() => _controlsVisible = true); - } else if (!widget.playing) { + } else { widget.onTogglePlay(); } } @@ -632,11 +654,11 @@ class _PlaybackOverlayState extends State<_PlaybackOverlay> { Expanded( child: Stack( children: [ - if (widget.playing) + if (!widget.playing) Center( child: PlayerCenterToggle( key: const Key('player-play-toggle'), - playing: true, + playing: false, onTap: widget.onTogglePlay, ), ), diff --git a/test/player/player_fullscreen_test.dart b/test/player/player_fullscreen_test.dart index 21db0c5..6dc0fcb 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_hide_pause_toggle_when_playback_is_paused', ( + testWidgets('should_show_play_toggle_only_when_playback_is_paused', ( tester, ) async { await _pumpApp(tester); @@ -82,16 +82,18 @@ void main() { await tester.tap(find.byKey(const Key('detail-cta'))); await tester.pumpAndSettle(); - await tester.tap(find.byKey(const Key('player-play-toggle'))); - await tester.pumpAndSettle(); - expect(find.byKey(const Key('player-play-toggle')), findsNothing); - expect(find.byKey(const Key('player-controls-top')), findsOneWidget); - expect(find.byKey(const Key('player-controls-bottom')), findsOneWidget); 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); + + await tester.tap(find.byKey(const Key('player-play-toggle'))); + await tester.pump(); + expect(find.byKey(const Key('player-play-toggle')), findsNothing); }); testWidgets('should_keep_controls_visible_until_clear_screen_is_tapped', ( @@ -109,6 +111,10 @@ 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); + + await tester.tap(find.byKey(const Key('player-video-tap'))); + await tester.pump(); expect(find.byType(PlayerCenterToggle), findsOneWidget); await tester.pump(const Duration(seconds: 5)); @@ -176,6 +182,21 @@ void main() { expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget); expect(find.byKey(const Key('home-feed-scrim')), findsOneWidget); }); + + testWidgets('should_show_home_play_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')), findsNothing); + await tester.tap(find.byKey(const Key('home-feed-video-toggle'))); + await tester.pump(); + expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); + + await tester.tap(find.byKey(const Key('home-feed-center-play'))); + await tester.pump(); + expect(find.byKey(const Key('home-feed-center-play')), findsNothing); + }); } void _expectFullscreenOverlay(WidgetTester tester) { @@ -185,7 +206,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);