fix(player): 修复切集返回推荐页黑屏

This commit is contained in:
Zhou Weidong committed 2026-10-26 16:20:31 +08:00
1 parent 9d2d3b97a1
commit 440188f261
5 files changed
+297 -37

No files matched your search

+113 -23
View File
@@ -95,9 +95,7 @@ void main() {
await tester.tap(find.byKey(const Key('tab-recommend')));
await tester.pumpAndSettle();
final recommendPlayer = find.byKey(
const Key('recommend-feed-player'),
);
final recommendPlayer = find.byKey(const Key('recommend-feed-player'));
final renderStack = find.descendant(
of: recommendPlayer,
matching: find.byType(PlayerRenderStack),
@@ -107,15 +105,12 @@ void main() {
final playerState = tester.state(recommendPlayer);
final currentSurface = find.descendant(
of: recommendPlayer,
matching: find.byKey(
const ValueKey('player-render-slot-current'),
),
matching: find.byKey(const ValueKey('player-render-slot-current')),
);
final sourceRender = tester.widget<PlayerRenderStack>(renderStack);
final sourceIndex =
sourceRender.slots[PlayerRenderSlotRole.current]?.index;
final sourceIndex = sourceRender.slots[PlayerRenderSlotRole.current]?.index;
final currentEpisodeId = factory.episodes.first.id;
final controller = factory.created.first.controller;
final createdBefore = factory.created.length;
final requestsBefore = playback.requests.length;
expect(controller.value.position, const Duration(seconds: 5));
expect(
@@ -132,20 +127,24 @@ void main() {
final fullPlayer = tester.widget<PlayerPage>(find.byType(PlayerPage));
expect(fullPlayer.homeMode, isFalse);
expect(fullPlayer.handoff, isNotNull);
expect(fullPlayer.handoff!.initialIndex, sourceIndex);
expect(fullPlayer.handoff!.logic.session.currentIndex, sourceIndex);
expect(fullPlayer.handoff!.sourceIndex, sourceIndex);
expect(
fullPlayer.handoff!.logic.session.currentIndex,
fullPlayer.handoff!.episodeIndex,
);
expect(find.byKey(const Key('home-tabs-bar')), findsNothing);
expect(find.byKey(const Key('recommend-top-nav')), findsNothing);
expect(find.byKey(const Key('home-feed-gesture')), findsNothing);
expect(find.byKey(const Key('player-back')), findsOneWidget);
expect(factory.created.length, createdBefore);
expect(
factory.episodes.where((episode) => episode.id == currentEpisodeId),
hasLength(1),
);
expect(playback.requests.length, requestsBefore);
expect(controller.value.position, const Duration(seconds: 5));
final fullCurrentSurface = find.descendant(
of: find.byType(PlayerPage),
matching: find.byKey(
const ValueKey('player-render-slot-current'),
),
matching: find.byKey(const ValueKey('player-render-slot-current')),
);
expect(
find.descendant(
@@ -165,7 +164,10 @@ void main() {
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
expect(recommendPlayer, findsOneWidget);
expect(renderStack, findsOneWidget);
expect(factory.created.length, createdBefore);
expect(
factory.episodes.where((episode) => episode.id == currentEpisodeId),
hasLength(1),
);
expect(playback.requests.length, requestsBefore);
expect(controller.value.position, const Duration(seconds: 5));
expect(find.byKey(const Key('home-tabs-bar')), findsOneWidget);
@@ -195,6 +197,10 @@ void main() {
await tester.tap(find.byKey(const Key('home-feed-full-series')));
await tester.pumpAndSettle();
final fullPlayer = tester.widget<PlayerPage>(find.byType(PlayerPage));
final handoff = fullPlayer.handoff!;
final dramaId = handoff.seriesDrama.id;
final firstEpisodeId = handoff.logic.session.currentEpisode.id;
final createdBefore = factory.created.length;
await tester.drag(
find.byKey(const Key('player-video-tap')),
@@ -205,8 +211,44 @@ void main() {
expect(find.byType(PlayerPage), findsOneWidget);
expect(factory.created.length, lessThanOrEqualTo(createdBefore + 1));
expect(find.byKey(const Key('player-render-stack')), findsOneWidget);
final switchedEpisode = handoff.logic.session.currentEpisode;
expect(switchedEpisode.id, isNot(firstEpisodeId));
expect(switchedEpisode.number, 2);
expect(
handoff.logic.queue.entryAt(handoff.logic.session.currentIndex).drama.id,
dramaId,
);
expect(handoff.logic.session.userWantsPlay, isTrue);
expect(
factory.episodes.where((episode) => episode.id == switchedEpisode.id),
hasLength(1),
);
final switchedVideo = handoff.logic.session.active! as VideoPlayerPort;
final switchedController = switchedVideo.controller;
await tester.tap(find.byKey(const Key('player-back')));
await tester.pumpAndSettle();
expect(handoff.logic.session.currentIndex, handoff.sourceIndex);
expect(
handoff.logic.queue.entryAt(handoff.sourceIndex).episode.id,
switchedEpisode.id,
);
final sourceCurrentSurface = find.descendant(
of: find.byType(PlayerPage),
matching: find.byKey(const ValueKey('player-render-slot-current')),
);
expect(
tester.widget<PlayerVideoSurface>(sourceCurrentSurface).controller,
same(switchedController),
);
expect(switchedController.value.position, const Duration(seconds: 5));
expect(
find.descendant(
of: sourceCurrentSurface,
matching: find.byKey(const Key('player-single-placeholder')),
),
findsNothing,
);
});
testWidgets('should_show_one_paused_overlay_when_entering_full_player', (
@@ -236,6 +278,48 @@ void main() {
expect(find.byKey(const Key('home-tabs-bar')), findsOneWidget);
});
testWidgets('should_keep_drama_and_episode_indices_separate', (tester) async {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('tab-recommend')));
await tester.pumpAndSettle();
final feedPage = find
.descendant(
of: find.byKey(const Key('recommend-feed-player')),
matching: find.byType(PageView),
)
.first;
await tester.drag(feedPage, const Offset(0, -620));
await tester.pumpAndSettle();
final sourceRender = tester.widget<PlayerRenderStack>(
find.byType(PlayerRenderStack),
);
final sourceIndex = sourceRender.slots[PlayerRenderSlotRole.current]?.index;
expect(sourceIndex, isNotNull);
expect(sourceIndex, greaterThan(0));
final feedIndex = sourceIndex!;
await tester.tap(find.byKey(const Key('home-feed-full-series')));
await tester.pumpAndSettle();
final fullPlayer = tester.widget<PlayerPage>(find.byType(PlayerPage));
final handoff = fullPlayer.handoff!;
expect(handoff.sourceIndex, feedIndex);
expect(handoff.episodeIndex, 0);
expect(handoff.logic.session.currentIndex, handoff.episodeIndex);
expect(
handoff.seriesDrama.id,
handoff.sourceQueue.entryAt(feedIndex).drama.id,
);
expect(
handoff.logic.session.currentEpisode.id,
handoff.sourceEpisodes[feedIndex].id,
);
await tester.tap(find.byKey(const Key('player-back')));
await tester.pumpAndSettle();
});
testWidgets('should_render_player_loading_indicators_at_compact_size', (
tester,
) async {
@@ -940,10 +1024,7 @@ void main() {
),
],
);
await _pumpApp(
tester,
catalog: FakeCatalogRepository(dramas: [longCopy]),
);
await _pumpApp(tester, catalog: FakeCatalogRepository(dramas: [longCopy]));
await _openSeriesPlayer(
tester,
cardKey: const Key('home-feed-card-long-copy-demo'),
@@ -966,7 +1047,9 @@ void main() {
);
expect(tester.widget<Text>(synopsis).maxLines, 2);
expect(
tester.widget<Padding>(find.byKey(const Key('player-synopsis-gap'))).padding,
tester
.widget<Padding>(find.byKey(const Key('player-synopsis-gap')))
.padding,
const EdgeInsets.only(left: 6),
);
final synopsisRect = tester.getRect(synopsis);
@@ -983,10 +1066,15 @@ void main() {
find.descendant(of: toggle, matching: find.text('Less')),
findsOneWidget,
);
expect(tester.widget<Text>(find.byKey(const Key('player-synopsis'))).maxLines, isNull);
expect(
tester.widget<Text>(find.byKey(const Key('player-synopsis'))).maxLines,
isNull,
);
final lessRect = tester.getRect(toggle);
final textRect = tester.getRect(find.byKey(const Key('player-synopsis')));
final block = tester.getRect(find.byKey(const Key('player-episode-synopsis')));
final block = tester.getRect(
find.byKey(const Key('player-episode-synopsis')),
);
expect(lessRect.top, greaterThanOrEqualTo(textRect.bottom - 1));
expect(block.right - lessRect.right, lessThanOrEqualTo(2));
@@ -1596,10 +1684,12 @@ Future<void> _pumpApp(
class _RouteVideoFactory {
final List<_RouteVideoPlayer> created = [];
final List<Episode> episodes = [];
PlayerPort create(Episode episode) {
final player = _RouteVideoPlayer(episode);
created.add(player);
episodes.add(episode);
return player;
}
}