fix(player): 完善进度预览清屏与下拉刷新

This commit is contained in:
Zhou Weidong committed 2026-10-23 03:18:24 +08:00
1 parent 9b1afbdb36
commit f8500bbaca
15 files changed
+949 -251

No files matched your search

+1 -1
View File
@@ -294,7 +294,7 @@ void main() {
expect(find.textContaining('/ 00:12'), findsOneWidget);
expect(
tester.getSize(find.byKey(const Key('scrub-preview-card'))).width,
120,
96,
);
await gesture.up();
+61 -14
View File
@@ -570,14 +570,11 @@ void main() {
32,
);
await tester.tap(find.byKey(const Key('player-synopsis-toggle')));
await tester.pumpAndSettle();
final expandedBottom = tester.getRect(
final bottomPanel = tester.getRect(
find.byKey(const Key('player-controls-bottom')),
);
// K29.9 展开态展示简介全文,高度会增长,但仍需留在画面下半区。
expect(expandedBottom.height, lessThanOrEqualTo(330));
expect(expandedBottom.top, greaterThanOrEqualTo(screenHeight * 0.5));
expect(bottomPanel.height, lessThanOrEqualTo(330));
expect(bottomPanel.top, greaterThanOrEqualTo(screenHeight * 0.5));
expect(tester.takeException(), isNull);
});
@@ -753,8 +750,33 @@ void main() {
});
testWidgets('should_toggle_synopsis_with_inline_text_button', (tester) async {
await _pumpApp(tester);
await _openSeriesPlayer(tester);
final longCopy = Drama(
id: 'long-copy-demo',
title: 'Long Title',
synopsis:
'A very long synopsis that keeps describing the story far beyond '
'the two lines available under the title in the fullscreen player.',
posterUrl: '/files/long-copy-demo.png',
genre: 'Drama',
detailLoaded: true,
episodes: const [
Episode(
id: 'long-copy-demo-1',
number: 1,
title: 'Episode 1',
isFree: true,
videoUrl: 'https://example.test/long-demo-1.mp4',
),
],
);
await _pumpApp(
tester,
catalog: FakeCatalogRepository(dramas: [longCopy]),
);
await _openSeriesPlayer(
tester,
cardKey: const Key('home-feed-card-long-copy-demo'),
);
final toggle = find.byKey(const Key('player-synopsis-toggle'));
final synopsis = find.byKey(const Key('player-synopsis'));
@@ -762,10 +784,26 @@ void main() {
find.descendant(of: toggle, matching: find.text('More')),
findsOneWidget,
);
expect(tester.widget<Text>(synopsis).maxLines, 1);
expect(
tester.getRect(toggle).left - tester.getRect(synopsis).right,
lessThanOrEqualTo(4),
tester
.widget<Text>(
find.descendant(of: toggle, matching: find.text('More')),
)
.style
?.color,
AppColors.textPrimary,
);
expect(tester.widget<Text>(synopsis).maxLines, 2);
expect(
tester.widget<Padding>(find.byKey(const Key('player-synopsis-gap'))).padding,
const EdgeInsets.only(left: 6),
);
final synopsisRect = tester.getRect(synopsis);
final toggleRect = tester.getRect(toggle);
expect(toggleRect.left, greaterThan(synopsisRect.left));
expect(
toggleRect.center.dy,
greaterThan(synopsisRect.top + synopsisRect.height * 0.45),
);
await tester.tap(toggle);
@@ -774,7 +812,12 @@ void main() {
find.descendant(of: toggle, matching: find.text('Less')),
findsOneWidget,
);
expect(tester.widget<Text>(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')));
expect(lessRect.top, greaterThanOrEqualTo(textRect.bottom - 1));
expect(block.right - lessRect.right, lessThanOrEqualTo(2));
await tester.tap(toggle);
await tester.pumpAndSettle();
@@ -782,7 +825,7 @@ void main() {
find.descendant(of: toggle, matching: find.text('More')),
findsOneWidget,
);
expect(tester.widget<Text>(synopsis).maxLines, 1);
expect(tester.widget<Text>(synopsis).maxLines, 2);
});
testWidgets('should_share_one_muted_style_across_label_and_synopsis', (
@@ -860,7 +903,11 @@ void main() {
final synopsis = tester.widget<Text>(
find.byKey(const Key('player-synopsis')),
);
expect(synopsis.maxLines, 1);
expect(
tester.getRect(find.byKey(const Key('player-synopsis'))).right,
lessThanOrEqualTo(320 - 14 - 54),
);
expect(synopsis.maxLines, 2);
expect(synopsis.overflow, TextOverflow.ellipsis);
expect(
tester.getRect(find.byKey(const Key('player-episodes-pill'))).right,
+3
View File
@@ -140,6 +140,9 @@ class _FakeAxisSource extends ChangeNotifier
Duration position,
) => frame;
@override
Future<void> prepareAt(String? thumbnailsUrl, Duration position) async {}
@override
bool hasAxis(String? thumbnailsUrl) => axisReady;
}
+142
View File
@@ -5,6 +5,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/data/models/drama.dart';
import 'package:fruitshorts/l10n/app_localizations.dart';
import 'package:fruitshorts/pages/player/widgets/home_feed_overlay.dart';
import 'package:fruitshorts/pages/player/widgets/player_overlay.dart';
import 'package:fruitshorts/pages/player/widgets/player_overlay_models.dart';
import 'package:fruitshorts/pages/player/widgets/seek_progress_bar.dart';
import 'package:video_player/video_player.dart';
@@ -151,6 +153,56 @@ void main() {
await gesture.up();
await tester.pumpAndSettle();
});
testWidgets('full player drag clears chrome and release restores it', (
tester,
) async {
await _pumpFullPlayerOverlay(tester);
expect(find.byKey(const Key('player-controls-top')), findsOneWidget);
expect(find.byKey(const Key('player-bottom-actions')), findsOneWidget);
final gesture = await tester.startGesture(
tester.getCenter(find.byKey(const Key('player-progress'))),
);
await gesture.moveBy(const Offset(80, 0));
await tester.pump();
expect(_opacity(tester, const Key('player-controls-top')), 0);
expect(_opacity(tester, const Key('player-interaction-rail')), 0);
expect(_offstage(tester, const Key('player-controls-bottom')), isTrue);
expect(_offstage(tester, const Key('player-bottom-actions')), isTrue);
expect(find.byKey(const Key('player-progress')), findsOneWidget);
await gesture.up();
await tester.pumpAndSettle();
expect(_opacity(tester, const Key('player-controls-top')), 1);
expect(_opacity(tester, const Key('player-interaction-rail')), 1);
expect(_offstage(tester, const Key('player-bottom-actions')), isFalse);
});
}
double _opacity(WidgetTester tester, Key key) {
return tester
.widget<Opacity>(
find
.ancestor(of: find.byKey(key), matching: find.byType(Opacity))
.first,
)
.opacity;
}
bool _offstage(WidgetTester tester, Key key) {
return tester
.widget<Offstage>(
find
.ancestor(
of: find.byKey(key, skipOffstage: false),
matching: find.byType(Offstage),
)
.first,
)
.offstage;
}
Future<_HarnessState> _pumpHarness(WidgetTester tester) async {
@@ -245,6 +297,96 @@ Future<ValueNotifier<VideoPlayerValue>> _pumpFeedOverlay(
return controller;
}
class _FullPlayerHarness extends StatefulWidget {
const _FullPlayerHarness({required this.controller});
final ValueNotifier<VideoPlayerValue> controller;
@override
State<_FullPlayerHarness> createState() => _FullPlayerHarnessState();
}
class _FullPlayerHarnessState extends State<_FullPlayerHarness> {
bool _scrubbing = false;
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
return PlayerPlaybackOverlay(
scrubbing: _scrubbing,
controlsVisible: true,
data: PlayerOverlayData(
l10n: l10n,
drama: const Drama(
id: 'full-drama',
title: 'Full Drama',
synopsis: 'A short synopsis for the full player.',
posterUrl: '',
totalEpisodes: 8,
detailLoaded: true,
),
episode: const Episode(
id: 'full-episode',
number: 2,
title: 'Episode 2',
isFree: true,
),
controller: widget.controller,
locked: false,
liked: false,
likeCount: 1,
commentCount: 1,
favoriteCount: 1,
saved: false,
playing: true,
playbackSpeed: 1,
totalEpisodes: 8,
boosting: false,
),
actions: PlayerOverlayActions(
onBack: () {},
onTogglePlay: () {},
onClear: () {},
onExitClear: () {},
onDetail: () {},
onSpeed: () {},
onEpisodes: () {},
onComments: () {},
onLike: () {},
onSave: () {},
onShare: () {},
onMore: () {},
onScrubStart: () => setState(() => _scrubbing = true),
onScrubEnd: () => setState(() => _scrubbing = false),
onSeek: (_) async {},
onLongPressCenter: () {},
onBoostStart: () {},
onBoostEnd: () {},
),
);
}
}
Future<void> _pumpFullPlayerOverlay(WidgetTester tester) async {
final controller = ValueNotifier<VideoPlayerValue>(
const VideoPlayerValue(
duration: Duration(minutes: 2),
position: Duration(seconds: 20),
isInitialized: true,
),
);
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
locale: const Locale('en'),
supportedLocales: AppLocalizations.supportedLocales,
localizationsDelegates: AppLocalizations.localizationsDelegates,
home: Scaffold(body: _FullPlayerHarness(controller: controller)),
),
);
await tester.pumpAndSettle();
}
class _Harness extends StatefulWidget {
const _Harness({super.key, required this.controller});