Instrument CurvedAnimation. (#143007)

This commit is contained in:
Polina Cherkasova 2024-02-06 19:26:40 -08:00 committed by GitHub
parent 10f1e63579
commit ac5c3dec87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View file

@ -379,6 +379,15 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
required this.curve,
this.reverseCurve,
}) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/animation.dart',
className: '$CurvedAnimation',
object: this,
);
}
_updateCurveDirection(parent.status);
parent.addStatusListener(_updateCurveDirection);
}
@ -433,6 +442,11 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
/// Cleans up any listeners added by this CurvedAnimation.
void dispose() {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
isDisposed = true;
parent.removeStatusListener(_updateCurveDirection);
}

View file

@ -512,4 +512,19 @@ FlutterError
expect(animation.value, 10.0);
});
test('$CurvedAnimation dispatches memory events', () async {
await expectLater(
await memoryEvents(
() => CurvedAnimation(
parent: AnimationController(
duration: const Duration(milliseconds: 100),
vsync: const TestVSync(),
),
curve: Curves.linear,
).dispose(),
CurvedAnimation,
),
areCreateAndDispose,
);
});
}