fix(player): 改用墙钟驱动飘心动画
This commit is contained in:
1 parent
c0f65042e6
commit
978c309cd7
6 files changed
+235
-100
No files matched your search
@@ -48,7 +48,6 @@ void main() {
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -94,7 +93,7 @@ void main() {
|
||||
await tester.tapAt(center);
|
||||
await tester.pump();
|
||||
expect(repository.likeTargets, hasLength(1));
|
||||
await tester.pump(const Duration(milliseconds: 2300));
|
||||
await _pumpTestClock(tester, clock, const Duration(milliseconds: 1600));
|
||||
|
||||
clock.advance(const Duration(milliseconds: 500));
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
@@ -136,24 +135,19 @@ void main() {
|
||||
final burstFinder = find.byType(PlayerDoubleTapHeartBurst);
|
||||
final gestureState = tester.state(gestureFinder);
|
||||
final burstState = tester.state(burstFinder);
|
||||
var elapsedMs = 100;
|
||||
|
||||
for (var index = 0; index < 30; index++) {
|
||||
key.currentState!.rebuild();
|
||||
clock.advance(const Duration(milliseconds: 16));
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
elapsedMs += 16;
|
||||
}
|
||||
|
||||
expect(tester.state(gestureFinder), same(gestureState));
|
||||
expect(tester.state(burstFinder), same(burstState));
|
||||
expect(find.byKey(const Key('double-tap-heart-0')), findsOneWidget);
|
||||
|
||||
while (burstFinder.evaluate().isNotEmpty && elapsedMs < 2000) {
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
elapsedMs += 16;
|
||||
}
|
||||
await _pumpTestClock(tester, clock, const Duration(milliseconds: 1600));
|
||||
expect(burstFinder, findsNothing);
|
||||
expect(elapsedMs, greaterThanOrEqualTo(1500));
|
||||
});
|
||||
|
||||
testWidgets('heart burst starts at tapped location', (tester) async {
|
||||
@@ -192,17 +186,21 @@ void main() {
|
||||
};
|
||||
var elapsedMs = 0;
|
||||
try {
|
||||
final clock = _TestClock();
|
||||
final key = GlobalKey<_RemovableGestureHarnessState>();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: _RemovableGestureHarness(key: key)),
|
||||
MaterialApp(
|
||||
home: _RemovableGestureHarness(key: key, clock: clock),
|
||||
),
|
||||
);
|
||||
const tapPosition = Offset(120, 220);
|
||||
|
||||
await tester.tapAt(tapPosition);
|
||||
clock.advance(const Duration(milliseconds: 100));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.tapAt(tapPosition);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await _pumpTestClock(tester, clock, const Duration(milliseconds: 100));
|
||||
|
||||
final burstFinder = find.byType(PlayerDoubleTapHeartBurst);
|
||||
expect(burstFinder, findsOneWidget);
|
||||
@@ -212,10 +210,8 @@ void main() {
|
||||
expect(burstFinder, findsOneWidget);
|
||||
|
||||
elapsedMs = 100;
|
||||
while (burstFinder.evaluate().isNotEmpty && elapsedMs < 2000) {
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
elapsedMs += 16;
|
||||
}
|
||||
await _pumpTestClock(tester, clock, const Duration(milliseconds: 1600));
|
||||
elapsedMs += 1600;
|
||||
expect(burstFinder, findsNothing);
|
||||
} finally {
|
||||
debugPrint = originalDebugPrint;
|
||||
@@ -380,7 +376,9 @@ class _HarnessState extends State<_Harness> {
|
||||
}
|
||||
|
||||
class _RemovableGestureHarness extends StatefulWidget {
|
||||
const _RemovableGestureHarness({super.key});
|
||||
const _RemovableGestureHarness({super.key, required this.clock});
|
||||
|
||||
final _TestClock clock;
|
||||
|
||||
@override
|
||||
State<_RemovableGestureHarness> createState() =>
|
||||
@@ -415,6 +413,7 @@ class _RemovableGestureHarnessState extends State<_RemovableGestureHarness> {
|
||||
gestureKey: const Key('removable-gesture'),
|
||||
enabled: true,
|
||||
doubleTapEnabled: true,
|
||||
now: widget.clock.now,
|
||||
onSingleTap: () {},
|
||||
onDoubleTapLike: (_) {},
|
||||
onLongPressStart: (_, _) {},
|
||||
@@ -437,3 +436,18 @@ class _TestClock {
|
||||
_now = _now.add(duration);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pumpTestClock(
|
||||
WidgetTester tester,
|
||||
_TestClock clock,
|
||||
Duration duration,
|
||||
) async {
|
||||
const frameMs = 16;
|
||||
var remainingMs = duration.inMilliseconds;
|
||||
while (remainingMs > 0) {
|
||||
final stepMs = remainingMs >= frameMs ? frameMs : remainingMs;
|
||||
clock.advance(Duration(milliseconds: stepMs));
|
||||
await tester.pump(const Duration(milliseconds: frameMs));
|
||||
remainingMs -= stepMs;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user