Fix InkRipple.cancel animation race (#14442)
This commit is contained in:
@@ -199,9 +199,14 @@ class InkRipple extends InteractiveInkFeature {
|
||||
@override
|
||||
void cancel() {
|
||||
_fadeInController.stop();
|
||||
_fadeOutController
|
||||
..value = 1.0 - _fadeInController.value
|
||||
..animateTo(1.0, duration: _kCancelDuration);
|
||||
// Watch out: setting _fadeOutController's value to 1.0 would
|
||||
// trigger a call to _handleAlphaStatusChanged() which would
|
||||
// dispose _fadeOutController.
|
||||
if (_fadeInController.value > 0.0) {
|
||||
_fadeOutController
|
||||
..value = 1.0 - _fadeInController.value
|
||||
..animateTo(1.0, duration: _kCancelDuration);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleAlphaStatusChanged(AnimationStatus status) {
|
||||
|
||||
@@ -170,7 +170,7 @@ class InkSplash extends InteractiveInkFeature {
|
||||
|
||||
@override
|
||||
void cancel() {
|
||||
_alphaController.forward();
|
||||
_alphaController?.forward();
|
||||
}
|
||||
|
||||
void _handleAlphaStatusChanged(AnimationStatus status) {
|
||||
@@ -182,6 +182,7 @@ class InkSplash extends InteractiveInkFeature {
|
||||
void dispose() {
|
||||
_radiusController.dispose();
|
||||
_alphaController.dispose();
|
||||
_alphaController = null;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -248,4 +248,34 @@ void main() {
|
||||
|
||||
await gesture.up();
|
||||
});
|
||||
|
||||
testWidgets('Cancel an InkRipple that was disposed when its animation ended', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/14391
|
||||
await tester.pumpWidget(
|
||||
new Material(
|
||||
child: new Center(
|
||||
child: new Container(
|
||||
width: 100.0,
|
||||
height: 100.0,
|
||||
child: new InkWell(
|
||||
onTap: () { },
|
||||
radius: 100.0,
|
||||
splashFactory: InkRipple.splashFactory,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Offset tapDownOffset = tester.getTopLeft(find.byType(InkWell));
|
||||
await tester.tapAt(tapDownOffset);
|
||||
await tester.pump(); // start splash
|
||||
await tester.pump(const Duration(milliseconds: 375)); // _kFadeOutDuration, in_ripple.dart
|
||||
|
||||
final TestGesture gesture = await tester.startGesture(tapDownOffset);
|
||||
await tester.pump(); // start gesture
|
||||
await gesture.moveTo(const Offset(0.0, 0.0));
|
||||
await gesture.up(); // generates a tap cancel
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user