fix(player): 中心按钮仅暂停时显示

This commit is contained in:
Zhou Weidong committed 2026-10-19 17:20:19 +08:00
1 parent b1747afbe8
commit 71e317f4ab
2 files changed
+29 -83

No files matched your search

+12 -8
View File
@@ -451,11 +451,14 @@ class _PlayerPageState extends State<PlayerPage> with WidgetsBindingObserver {
), ),
), ),
), ),
if (widget.homeMode && !logic.chromeHidden && selected) if (widget.homeMode &&
!logic.chromeHidden &&
selected &&
!logic.session.userWantsPlay)
Center( Center(
child: PlayerCenterToggle( child: PlayerCenterToggle(
key: const Key('home-feed-center-play'), key: const Key('home-feed-center-play'),
playing: logic.session.userWantsPlay, playing: false,
onTap: () => onTap: () =>
logic.session.setUserWantsPlay(!logic.session.userWantsPlay), logic.session.setUserWantsPlay(!logic.session.userWantsPlay),
), ),
@@ -773,13 +776,14 @@ class _PlaybackOverlayState extends State<_PlaybackOverlay> {
onPressed: () => setState(() => _controlsVisible = true), onPressed: () => setState(() => _controlsVisible = true),
), ),
), ),
Center( if (!widget.playing)
child: PlayerCenterToggle( Center(
key: const Key('player-play-toggle'), child: PlayerCenterToggle(
playing: widget.playing, key: const Key('player-play-toggle'),
onTap: widget.onTogglePlay, playing: false,
onTap: widget.onTogglePlay,
),
), ),
),
], ],
), ),
); );
+17 -75
View File
@@ -69,7 +69,7 @@ void main() {
expect(tester.takeException(), isNull); 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 _pumpApp(tester);
await tester.binding.handlePopRoute(); await tester.binding.handlePopRoute();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
@@ -80,18 +80,11 @@ void main() {
await tester.tap(find.byKey(const Key('detail-cta'))); await tester.tap(find.byKey(const Key('detail-cta')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byKey(const Key('player-play-toggle')), findsOneWidget); expect(find.byKey(const Key('player-play-toggle')), findsNothing);
expect(
tester
.widget<PlayerCenterToggle>(
find.byKey(const Key('player-play-toggle')),
)
.playing,
isTrue,
);
await tester.tap(find.byKey(const Key('player-play-toggle'))); await tester.tapAt(const Offset(80, 300));
await tester.pump(); await tester.pump();
expect(find.byKey(const Key('player-play-toggle')), findsOneWidget);
expect( expect(
tester tester
.widget<PlayerCenterToggle>( .widget<PlayerCenterToggle>(
@@ -110,21 +103,7 @@ void main() {
await tester.tap(find.byKey(const Key('player-play-toggle'))); await tester.tap(find.byKey(const Key('player-play-toggle')));
await tester.pump(); await tester.pump();
expect( expect(find.byKey(const Key('player-play-toggle')), findsNothing);
tester
.widget<PlayerCenterToggle>(
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', ( 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-top')), findsOneWidget);
expect(find.byKey(const Key('player-controls-bottom')), 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.tapAt(const Offset(80, 300));
await tester.pump(); await tester.pump();
@@ -188,14 +167,7 @@ void main() {
await tester.pump(); await tester.pump();
expect(find.byKey(const Key('player-controls-top')), findsNothing); expect(find.byKey(const Key('player-controls-top')), findsNothing);
expect(find.byKey(const Key('player-exit-clear-screen')), findsOneWidget); expect(find.byKey(const Key('player-exit-clear-screen')), findsOneWidget);
expect( expect(find.byType(PlayerCenterToggle), findsNothing);
tester
.widget<PlayerCenterToggle>(
find.byKey(const Key('player-play-toggle')),
)
.playing,
isTrue,
);
await tester.tapAt(const Offset(80, 300)); await tester.tapAt(const Offset(80, 300));
await tester.pump(); 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-title')), findsOneWidget);
expect(find.byKey(const Key('home-feed-info-card')), 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-scrim')), findsOneWidget);
expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
expect(
tester
.widget<PlayerCenterToggle>(
find.byKey(const Key('home-feed-center-play')),
)
.playing,
isTrue,
);
await tester.tap(find.byKey(const Key('home-feed-clear-screen'))); await tester.tap(find.byKey(const Key('home-feed-clear-screen')));
await tester.pump(); await tester.pump();
@@ -277,7 +241,7 @@ void main() {
tester.getSize(find.byKey(const Key('home-feed-exit-clear-screen'))), tester.getSize(find.byKey(const Key('home-feed-exit-clear-screen'))),
const Size(36, 36), 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( expect(
find.ancestor( find.ancestor(
of: find.byKey(const Key('home-feed-exit-clear-screen')), 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')), find.byKey(const Key('home-feed-exit-clear-screen')),
findsOneWidget, findsOneWidget,
); );
expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget);
expect( expect(
tester tester
.widget<PlayerCenterToggle>( .widget<PlayerCenterToggle>(
@@ -315,14 +280,7 @@ void main() {
find.byKey(const Key('home-feed-exit-clear-screen')), find.byKey(const Key('home-feed-exit-clear-screen')),
findsOneWidget, findsOneWidget,
); );
expect( expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
tester
.widget<PlayerCenterToggle>(
find.byKey(const Key('home-feed-center-play')),
)
.playing,
isTrue,
);
await tester.tap(find.byKey(const Key('home-feed-exit-clear-screen'))); await tester.tap(find.byKey(const Key('home-feed-exit-clear-screen')));
await tester.pump(); 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-info-card')), findsOneWidget);
expect(find.byKey(const Key('home-feed-scrim')), 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-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, tester,
) async { ) async {
await _pumpApp(tester); await _pumpApp(tester);
await tester.tap(find.byKey(const Key('tab-home'))); await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
expect(
tester
.widget<PlayerCenterToggle>(
find.byKey(const Key('home-feed-center-play')),
)
.playing,
isTrue,
);
await tester.tapAt(const Offset(80, 300)); await tester.tapAt(const Offset(80, 300));
await tester.pump(); await tester.pump();
expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); 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.tap(find.byKey(const Key('home-feed-center-play')));
await tester.pump(); await tester.pump();
expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget); expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
expect(
tester
.widget<PlayerCenterToggle>(
find.byKey(const Key('home-feed-center-play')),
)
.playing,
isTrue,
);
}); });
testWidgets('should_keep_home_clear_state_when_swiping_to_next_page', ( 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')), find.byKey(const Key('home-feed-exit-clear-screen')),
findsOneWidget, 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')]) { for (final key in const [Key('player-back'), Key('player-more')]) {
expect(tester.getSize(find.byKey(key)), const Size(36, 36)); 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-episodes')), findsOneWidget);
expect(find.byKey(const Key('player-comments')), findsOneWidget); expect(find.byKey(const Key('player-comments')), findsOneWidget);
expect(find.byKey(const Key('player-next')), findsOneWidget); expect(find.byKey(const Key('player-next')), findsOneWidget);