fix(player): 优化加载指示器与锁定进度条

This commit is contained in:
Zhou Weidong committed 2026-10-22 10:09:33 +08:00
1 parent 7b068e8eb4
commit 623c184243
13 files changed
+393 -33

No files matched your search

+1 -2
View File
@@ -3,7 +3,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/theme/app_colors.dart';
import 'package:fruitshorts/pages/player/widgets/loading_progress_track.dart';
void main() {
@@ -37,7 +36,7 @@ void main() {
find.byKey(const Key('progress-loading-highlight')),
)
.color,
AppColors.blue,
Colors.white,
);
final initialLeft = tester
+89 -2
View File
@@ -65,6 +65,53 @@ void main() {
_expectPlayerNavigationBar(tester);
});
testWidgets('should_render_player_loading_indicators_at_compact_size', (
tester,
) async {
final playback = _PendingPlaybackRepository();
final initialization = Completer<void>();
await _pumpApp(
tester,
playback: playback,
playerFactory: (_) => _GatedPlayer(initialization.future),
settle: false,
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
final ticketLoading = find.byKey(const Key('player-ticket-loading'));
expect(ticketLoading, findsOneWidget);
expect(tester.getSize(ticketLoading), const Size(24, 24));
expect(
tester.widget<CircularProgressIndicator>(ticketLoading).strokeWidth,
2,
);
playback.ticket.complete(
const PlayTicket(
episodeId: 'city-lights-demo-1',
accessible: true,
accessType: PlayTicket.free,
playUrl: '/files/episode/fake-city.mp4?e=1&s=abc',
qualities: ['AUTO'],
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
final sessionLoading = find.byKey(const Key('player-session-loading'));
expect(sessionLoading, findsOneWidget);
expect(tester.getSize(sessionLoading), const Size(24, 24));
expect(
tester.widget<CircularProgressIndicator>(sessionLoading).strokeWidth,
2,
);
initialization.complete();
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
testWidgets('should_pause_and_resume_player_when_page_route_covers_it', (
tester,
) async {
@@ -956,6 +1003,16 @@ void main() {
tester,
cardKey: const Key('home-drama-card-locked-demo'),
);
expect(find.byKey(const Key('progress-loading')), findsNothing);
expect(find.byKey(const Key('progress-loading-highlight')), findsNothing);
expect(find.byKey(const Key('progress-inactive')), findsOneWidget);
expect(find.byType(Slider), findsNothing);
expect(
tester
.widget<SeekProgressBar>(find.byKey(const Key('player-progress')))
.locked,
isTrue,
);
await tester.tap(find.byKey(const Key('player-episodes')));
await tester.pumpAndSettle();
@@ -1293,10 +1350,11 @@ Future<void> _pumpApp(
WidgetTester tester, {
Size size = const Size(390, 844),
FakeCatalogRepository? catalog,
FakePlaybackRepository? playback,
PlaybackRepository? playback,
FakeInteractionRepository? interactions,
FakeCommentRepository? commentRepository,
PlayerFactory? playerFactory,
bool settle = true,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
@@ -1317,7 +1375,7 @@ Future<void> _pumpApp(
haptics: FakeHaptics(),
),
);
await tester.pumpAndSettle();
if (settle) await tester.pumpAndSettle();
}
const _countingDrama = Drama(
@@ -1361,6 +1419,35 @@ class _RecordingPlayer implements PlayerPort {
Future<void> dispose() async {}
}
class _PendingPlaybackRepository implements PlaybackRepository {
final Completer<PlayTicket> ticket = Completer<PlayTicket>();
@override
Future<PlayTicket> ticketFor(String episodeId, {bool forceRefresh = false}) =>
ticket.future;
@override
bool isFresh(String episodeId) => false;
}
class _GatedPlayer implements PlayerPort {
_GatedPlayer(this.initialization);
final Future<void> initialization;
@override
Future<void> initialize() => initialization;
@override
Future<void> play() async {}
@override
Future<void> pause() async {}
@override
Future<void> dispose() async {}
}
const _lockedDrama = Drama(
id: 'locked-demo',
title: 'Locked Demo',