Skip to content

Commit 680a819

Browse files
author
Jonah Williams
authored
[framework] ensure ink sparkle is disposed (#104569)
1 parent 09987dc commit 680a819

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

packages/flutter/lib/src/material/ink_sparkle.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ class InkSparkle extends InteractiveInkFeature {
135135
_animationController = AnimationController(
136136
duration: _animationDuration,
137137
vsync: controller.vsync,
138-
)..addListener(controller.markNeedsPaint)..forward();
138+
)..addListener(controller.markNeedsPaint)
139+
..addStatusListener(_handleStatusChanged)
140+
..forward();
139141

140142
_radiusScale = TweenSequence<double>(
141143
<TweenSequenceItem<double>>[
@@ -209,6 +211,11 @@ class InkSparkle extends InteractiveInkFeature {
209211
_turbulenceSeed = turbulenceSeed ?? math.Random().nextDouble() * 1000.0;
210212
}
211213

214+
void _handleStatusChanged(AnimationStatus status) {
215+
if (status == AnimationStatus.completed)
216+
dispose();
217+
}
218+
212219
static const Duration _animationDuration = Duration(milliseconds: 617);
213220
static const double _targetRadiusMultiplier = 2.3;
214221
static const double _rotateRight = math.pi * 0.0078125;
@@ -259,6 +266,8 @@ class InkSparkle extends InteractiveInkFeature {
259266

260267
@override
261268
void paintFeature(Canvas canvas, Matrix4 transform) {
269+
assert(_animationController.isAnimating);
270+
262271
// InkSparkle can only paint if its shader has been compiled.
263272
if (_InkSparkleFactory._shaderManager == null) {
264273
// Skipping paintFeature because the shader it relies on is not ready to

packages/flutter/lib/src/material/material.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,12 @@ class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController
557557

558558
bool absorbHitTest;
559559

560+
@visibleForTesting
561+
List<InkFeature>? get debugInkFeatures {
562+
if (kDebugMode)
563+
return _inkFeatures;
564+
return null;
565+
}
560566
List<InkFeature>? _inkFeatures;
561567

562568
@override

packages/flutter/test/material/ink_sparkle_test.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,23 @@ void main() {
4848
final Finder buttonFinder = find.text('Sparkle!');
4949
await tester.tap(buttonFinder);
5050
await tester.pump();
51-
await tester.pumpAndSettle();
51+
await tester.pump(const Duration(milliseconds: 200));
5252

5353
final MaterialInkController material = Material.of(tester.element(buttonFinder))!;
54-
await tester.pump(const Duration(milliseconds: 200));
5554
expect(material, paintsExactlyCountTimes(#drawRect, 1));
55+
56+
// ignore: avoid_dynamic_calls
57+
expect((material as dynamic).debugInkFeatures, hasLength(1));
58+
59+
await tester.pumpAndSettle();
60+
// ink feature is disposed.
61+
// ignore: avoid_dynamic_calls
62+
expect((material as dynamic).debugInkFeatures, isEmpty);
5663
},
5764
skip: kIsWeb, // [intended] SPIR-V shaders are not yet supported for web.
5865
);
5966

60-
testWidgets('InkSparkle default splashFactory paints with drawPaint when unbounded', (WidgetTester tester) async {
67+
testWidgets('InkSparkle default splashFactory paints with drawPaint when unbounded', (WidgetTester tester) async {
6168
await tester.pumpWidget(MaterialApp(
6269
home: Scaffold(
6370
body: Center(
@@ -72,10 +79,9 @@ void main() {
7279
final Finder buttonFinder = find.text('Sparkle!');
7380
await tester.tap(buttonFinder);
7481
await tester.pump();
75-
await tester.pumpAndSettle();
82+
await tester.pump(const Duration(milliseconds: 200));
7683

7784
final MaterialInkController material = Material.of(tester.element(buttonFinder))!;
78-
await tester.pump(const Duration(milliseconds: 200));
7985
expect(material, paintsExactlyCountTimes(#drawPaint, 1));
8086
},
8187
skip: kIsWeb, // [intended] SPIR-V shaders are not yet supported for web.

0 commit comments

Comments
 (0)