fix(player): 恢复develop飘心实现

This commit is contained in:
Zhou Weidong committed 2026-10-26 18:38:59 +08:00
1 parent 9039b27c7f
commit 84b24775d6
6 files changed
+107 -225

No files matched your search

+13 -62
View File
@@ -1,41 +1,24 @@
// Author: fruit.com.cn
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/pages/player/widgets/player_double_tap_hearts.dart';
void main() {
testWidgets('should_show_randomized_heart_particles_when_burst_starts', (
testWidgets('should_show_three_develop_hearts_when_burst_starts', (
tester,
) async {
final random = _RecordingRandom();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: PlayerDoubleTapHeartBurst(
burstId: 1,
onCompleted: _noop,
random: random,
),
),
const MaterialApp(
home: Scaffold(body: PlayerDoubleTapHeartBurst(onCompleted: _noop)),
),
);
await tester.pump(const Duration(milliseconds: 500));
await tester.pump(const Duration(milliseconds: 200));
final hearts = find.byIcon(Icons.favorite_rounded);
final count = hearts.evaluate().length;
expect(count, inInclusiveRange(6, 8));
for (var index = 0; index < count; index++) {
expect(_size(tester, index), inInclusiveRange(22, 34));
}
expect(random.intBounds.first, 3);
expect(random.intBounds.where((bound) => bound == 21), hasLength(7));
expect(random.intBounds.where((bound) => bound == 201), hasLength(8));
expect(random.intBounds.where((bound) => bound == 41), hasLength(8));
expect(random.intBounds.where((bound) => bound == 61), hasLength(8));
expect(random.intBounds.where((bound) => bound == 13), hasLength(8));
expect(find.byIcon(Icons.favorite_rounded), findsNWidgets(3));
expect(_size(tester, 0), 48);
expect(_size(tester, 1), 36);
expect(_size(tester, 2), 40);
expect(
tester
.widgetList<Stack>(
@@ -49,17 +32,7 @@ void main() {
);
});
test('heart particles fade from the start and scale in two phases', () {
expect(PlayerDoubleTapHeartBurst.opacityForProgress(0.5), lessThan(0.7));
expect(PlayerDoubleTapHeartBurst.scaleForProgress(0), 0.55);
expect(
PlayerDoubleTapHeartBurst.scaleForProgress(0.3),
closeTo(1.15, 1e-9),
);
expect(PlayerDoubleTapHeartBurst.scaleForProgress(1), closeTo(0.2, 1e-9));
});
testWidgets('heart burst completes around 1.2 to 1.4 seconds', (
testWidgets('develop heart burst completes after about 770ms', (
tester,
) async {
var completed = false;
@@ -67,25 +40,19 @@ void main() {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: PlayerDoubleTapHeartBurst(
burstId: 2,
random: _RecordingRandom(),
onCompleted: () => completed = true,
),
body: PlayerDoubleTapHeartBurst(onCompleted: () => completed = true),
),
),
);
while (!completed && elapsedMs < 2000) {
while (!completed && elapsedMs < 1200) {
await tester.pump(const Duration(milliseconds: 16));
elapsedMs += 16;
}
expect(completed, isTrue);
expect(elapsedMs, greaterThanOrEqualTo(1200));
expect(elapsedMs, lessThanOrEqualTo(1400));
final count = find.byIcon(Icons.favorite_rounded).evaluate().length;
expect(count, inInclusiveRange(6, 8));
expect(elapsedMs, greaterThanOrEqualTo(752));
expect(elapsedMs, lessThanOrEqualTo(800));
});
}
@@ -94,19 +61,3 @@ double _size(WidgetTester tester, int index) {
}
void _noop() {}
class _RecordingRandom implements Random {
final List<int> intBounds = [];
@override
bool nextBool() => true;
@override
double nextDouble() => 0.5;
@override
int nextInt(int max) {
intBounds.add(max);
return max - 1;
}
}