Unverified Commit e36a868b authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

TrainHoppingAnimation should dispatch creation and disposal events. (#141635)

parent 0503c447
...@@ -509,6 +509,15 @@ class TrainHoppingAnimation extends Animation<double> ...@@ -509,6 +509,15 @@ class TrainHoppingAnimation extends Animation<double>
this._nextTrain, { this._nextTrain, {
this.onSwitchedTrain, this.onSwitchedTrain,
}) { }) {
// 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: '$TrainHoppingAnimation',
object: this,
);
}
if (_nextTrain != null) { if (_nextTrain != null) {
if (_currentTrain!.value == _nextTrain!.value) { if (_currentTrain!.value == _nextTrain!.value) {
_currentTrain = _nextTrain; _currentTrain = _nextTrain;
...@@ -595,6 +604,11 @@ class TrainHoppingAnimation extends Animation<double> ...@@ -595,6 +604,11 @@ class TrainHoppingAnimation extends Animation<double>
/// After this is called, this object is no longer usable. /// After this is called, this object is no longer usable.
@override @override
void dispose() { void dispose() {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
assert(_currentTrain != null); assert(_currentTrain != null);
_currentTrain!.removeStatusListener(_statusChangeHandler); _currentTrain!.removeStatusListener(_statusChangeHandler);
_currentTrain!.removeListener(_valueChangeHandler); _currentTrain!.removeListener(_valueChangeHandler);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import '../scheduler/scheduler_tester.dart'; import '../scheduler/scheduler_tester.dart';
...@@ -127,6 +128,19 @@ void main() { ...@@ -127,6 +128,19 @@ void main() {
expect(animation.toString(), contains('no next')); expect(animation.toString(), contains('no next'));
}); });
test('TrainHoppingAnimation dispatches memory events', () async {
await expectLater(
await memoryEvents(
() => TrainHoppingAnimation(
const AlwaysStoppedAnimation<double>(1),
const AlwaysStoppedAnimation<double>(1),
).dispose(),
TrainHoppingAnimation,
),
areCreateAndDispose,
);
});
test('AnimationMean control test', () { test('AnimationMean control test', () {
final AnimationController left = AnimationController( final AnimationController left = AnimationController(
value: 0.5, value: 0.5,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment