Skip to content

Commit e36a868

Browse files
authored
TrainHoppingAnimation should dispatch creation and disposal events. (flutter#141635)
1 parent 0503c44 commit e36a868

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

packages/flutter/lib/src/animation/animations.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,15 @@ class TrainHoppingAnimation extends Animation<double>
509509
this._nextTrain, {
510510
this.onSwitchedTrain,
511511
}) {
512+
// TODO(polina-c): stop duplicating code across disposables
513+
// https://github.com/flutter/flutter/issues/137435
514+
if (kFlutterMemoryAllocationsEnabled) {
515+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
516+
library: 'package:flutter/animation.dart',
517+
className: '$TrainHoppingAnimation',
518+
object: this,
519+
);
520+
}
512521
if (_nextTrain != null) {
513522
if (_currentTrain!.value == _nextTrain!.value) {
514523
_currentTrain = _nextTrain;
@@ -595,6 +604,11 @@ class TrainHoppingAnimation extends Animation<double>
595604
/// After this is called, this object is no longer usable.
596605
@override
597606
void dispose() {
607+
// TODO(polina-c): stop duplicating code across disposables
608+
// https://github.com/flutter/flutter/issues/137435
609+
if (kFlutterMemoryAllocationsEnabled) {
610+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
611+
}
598612
assert(_currentTrain != null);
599613
_currentTrain!.removeStatusListener(_statusChangeHandler);
600614
_currentTrain!.removeListener(_valueChangeHandler);

packages/flutter/test/animation/animations_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:flutter/widgets.dart';
66
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
78

89
import '../scheduler/scheduler_tester.dart';
910

@@ -127,6 +128,19 @@ void main() {
127128
expect(animation.toString(), contains('no next'));
128129
});
129130

131+
test('TrainHoppingAnimation dispatches memory events', () async {
132+
await expectLater(
133+
await memoryEvents(
134+
() => TrainHoppingAnimation(
135+
const AlwaysStoppedAnimation<double>(1),
136+
const AlwaysStoppedAnimation<double>(1),
137+
).dispose(),
138+
TrainHoppingAnimation,
139+
),
140+
areCreateAndDispose,
141+
);
142+
});
143+
130144
test('AnimationMean control test', () {
131145
final AnimationController left = AnimationController(
132146
value: 0.5,

0 commit comments

Comments
 (0)