fix(player): 使用根Overlay渲染飘心
This commit is contained in:
1 parent
30b43878ab
commit
9039b27c7f
3 files changed
+63
-81
No files matched your search
@@ -10,25 +10,32 @@ void main() {
|
||||
testWidgets('should_show_randomized_heart_particles_when_burst_starts', (
|
||||
tester,
|
||||
) async {
|
||||
final random = _RecordingRandom();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: PlayerDoubleTapHeartBurst(
|
||||
burstId: 1,
|
||||
onCompleted: _noop,
|
||||
random: Random(42),
|
||||
random: random,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
|
||||
final hearts = find.byIcon(Icons.favorite_rounded);
|
||||
final count = hearts.evaluate().length;
|
||||
expect(count, inInclusiveRange(4, 5));
|
||||
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(
|
||||
tester
|
||||
.widgetList<Stack>(
|
||||
@@ -50,11 +57,9 @@ void main() {
|
||||
closeTo(1.15, 1e-9),
|
||||
);
|
||||
expect(PlayerDoubleTapHeartBurst.scaleForProgress(1), closeTo(0.2, 1e-9));
|
||||
expect(PlayerDoubleTapHeartBurst.minParticleCount, 4);
|
||||
expect(PlayerDoubleTapHeartBurst.maxParticleCount, 5);
|
||||
});
|
||||
|
||||
testWidgets('heart burst completes after at least two simulated seconds', (
|
||||
testWidgets('heart burst completes around 1.2 to 1.4 seconds', (
|
||||
tester,
|
||||
) async {
|
||||
var completed = false;
|
||||
@@ -64,23 +69,23 @@ void main() {
|
||||
home: Scaffold(
|
||||
body: PlayerDoubleTapHeartBurst(
|
||||
burstId: 2,
|
||||
random: Random(7),
|
||||
random: _RecordingRandom(),
|
||||
onCompleted: () => completed = true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
while (!completed && elapsedMs < 4000) {
|
||||
while (!completed && elapsedMs < 2000) {
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
elapsedMs += 16;
|
||||
}
|
||||
|
||||
expect(completed, isTrue);
|
||||
expect(elapsedMs, greaterThanOrEqualTo(2000));
|
||||
expect(elapsedMs, lessThanOrEqualTo(2600));
|
||||
expect(elapsedMs, greaterThanOrEqualTo(1200));
|
||||
expect(elapsedMs, lessThanOrEqualTo(1400));
|
||||
final count = find.byIcon(Icons.favorite_rounded).evaluate().length;
|
||||
expect(count, inInclusiveRange(4, 5));
|
||||
expect(count, inInclusiveRange(6, 8));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -89,3 +94,19 @@ 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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user