From aeb500a0604a0ffd9fa0ab71e0f4496d146871b3 Mon Sep 17 00:00:00 2001 From: Kostia Sokolovskyi Date: Fri, 27 Oct 2023 01:23:33 +0200 Subject: [PATCH] AnimationController should dispatch creation in constructor. (#134839) --- .../src/animation/animation_controller.dart | 18 +++++++++++++ .../flutter/lib/src/cupertino/slider.dart | 7 +++++ .../lib/src/material/mergeable_material.dart | 11 +++++++- .../flutter/lib/src/material/popup_menu.dart | 6 +++++ .../flutter/lib/src/material/scaffold.dart | 1 + .../animation/animation_controller_test.dart | 14 ++++++++++ .../flutter/test/animation/futures_test.dart | 9 +++++++ .../animation/iteration_patterns_test.dart | 1 + .../flutter/test/flutter_test_config.dart | 10 ++++++- .../test/material/bottom_sheet_test.dart | 26 ++++++++++++------- .../test/material/refresh_indicator_test.dart | 1 + .../animated_opacity_repaint_test.dart | 5 ++-- .../test/widgets/fade_transition_test.dart | 1 + .../test/widgets/list_view_misc_test.dart | 1 + .../flutter/test/widgets/magnifier_test.dart | 1 + .../test/widgets/status_transitions_test.dart | 1 + .../test/widgets/ticker_provider_test.dart | 10 +++---- .../test/widgets/transitions_test.dart | 16 ++++++++++++ 18 files changed, 120 insertions(+), 19 deletions(-) diff --git a/packages/flutter/lib/src/animation/animation_controller.dart b/packages/flutter/lib/src/animation/animation_controller.dart index 2a5f7e9850..dbc71d712c 100644 --- a/packages/flutter/lib/src/animation/animation_controller.dart +++ b/packages/flutter/lib/src/animation/animation_controller.dart @@ -20,6 +20,8 @@ export 'package:flutter/scheduler.dart' show TickerFuture, TickerProvider; export 'animation.dart' show Animation, AnimationStatus; export 'curves.dart' show Curve; +const String _flutterAnimationLibrary = 'package:flutter/animation.dart'; + // Examples can assume: // late AnimationController _controller, fadeAnimationController, sizeAnimationController; // late bool dismissed; @@ -244,6 +246,7 @@ class AnimationController extends Animation required TickerProvider vsync, }) : assert(upperBound >= lowerBound), _direction = _AnimationDirection.forward { + _maybeDispatchObjectCreation(); _ticker = vsync.createTicker(_tick); _internalSetValue(value ?? lowerBound); } @@ -275,10 +278,22 @@ class AnimationController extends Animation }) : lowerBound = double.negativeInfinity, upperBound = double.infinity, _direction = _AnimationDirection.forward { + _maybeDispatchObjectCreation(); _ticker = vsync.createTicker(_tick); _internalSetValue(value); } + /// Dispatches event of object creation to [MemoryAllocations.instance]. + void _maybeDispatchObjectCreation() { + if (kFlutterMemoryAllocationsEnabled) { + MemoryAllocations.instance.dispatchObjectCreated( + library: _flutterAnimationLibrary, + className: '$AnimationController', + object: this, + ); + } + } + /// The value at which this animation is deemed to be dismissed. final double lowerBound; @@ -800,6 +815,9 @@ class AnimationController extends Animation } return true; }()); + if (kFlutterMemoryAllocationsEnabled) { + MemoryAllocations.instance.dispatchObjectDisposed(object: this); + } _ticker!.dispose(); _ticker = null; clearStatusListeners(); diff --git a/packages/flutter/lib/src/cupertino/slider.dart b/packages/flutter/lib/src/cupertino/slider.dart index 50a6d29e4b..921f74423a 100644 --- a/packages/flutter/lib/src/cupertino/slider.dart +++ b/packages/flutter/lib/src/cupertino/slider.dart @@ -597,4 +597,11 @@ class _RenderCupertinoSlider extends RenderConstrainedBox implements MouseTracke @override bool get validForMouseTracker => false; + + @override + void dispose() { + _drag.dispose(); + _position.dispose(); + super.dispose(); + } } diff --git a/packages/flutter/lib/src/material/mergeable_material.dart b/packages/flutter/lib/src/material/mergeable_material.dart index d8a95d6747..f209555d0d 100644 --- a/packages/flutter/lib/src/material/mergeable_material.dart +++ b/packages/flutter/lib/src/material/mergeable_material.dart @@ -154,6 +154,14 @@ class _AnimationTuple { final CurvedAnimation endAnimation; final CurvedAnimation gapAnimation; double gapStart = 0.0; + + @mustCallSuper + void dispose() { + controller.dispose(); + startAnimation.dispose(); + endAnimation.dispose(); + gapAnimation.dispose(); + } } class _MergeableMaterialState extends State with TickerProviderStateMixin { @@ -208,7 +216,7 @@ class _MergeableMaterialState extends State with TickerProvid void dispose() { for (final MergeableMaterialItem child in _children) { if (child is MaterialGap) { - _animationTuples[child.key]!.controller.dispose(); + _animationTuples[child.key]!.dispose(); } } super.dispose(); @@ -258,6 +266,7 @@ class _MergeableMaterialState extends State with TickerProvid final MergeableMaterialItem child = _children.removeAt(index); if (child is MaterialGap) { + _animationTuples[child.key]!.dispose(); _animationTuples[child.key] = null; } } diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 520868c42d..107e8734d7 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -522,6 +522,12 @@ class _CheckedPopupMenuItemState extends PopupMenuItemState setState(() { /* animation changed */ })); } + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + @override void handleTap() { // This fades the checkmark in or out when tapped. diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 9f7e19b266..8967e74820 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -594,6 +594,7 @@ class ScaffoldMessengerState extends State with TickerProvide @override void dispose() { + _materialBannerController?.dispose(); _snackBarController?.dispose(); _snackBarTimer?.cancel(); _snackBarTimer = null; diff --git a/packages/flutter/test/animation/animation_controller_test.dart b/packages/flutter/test/animation/animation_controller_test.dart index 55bb776ca5..725a44fb7a 100644 --- a/packages/flutter/test/animation/animation_controller_test.dart +++ b/packages/flutter/test/animation/animation_controller_test.dart @@ -8,6 +8,7 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter/semantics.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; import '../scheduler/scheduler_tester.dart'; @@ -20,6 +21,19 @@ void main() { ..platformDispatcher.onDrawFrame = null; }); + test('AnimationController dispatches memory events', () async { + await expectLater( + await memoryEvents( + () => AnimationController( + duration: const Duration(milliseconds: 100), + vsync: const TestVSync(), + ).dispose(), + AnimationController, + ), + areCreateAndDispose, + ); + }); + test('Can set value during status callback', () { final AnimationController controller = AnimationController( duration: const Duration(milliseconds: 100), diff --git a/packages/flutter/test/animation/futures_test.dart b/packages/flutter/test/animation/futures_test.dart index 6ffee8e164..366014681d 100644 --- a/packages/flutter/test/animation/futures_test.dart +++ b/packages/flutter/test/animation/futures_test.dart @@ -13,14 +13,17 @@ void main() { duration: const Duration(milliseconds: 100), vsync: const TestVSync(), ); + addTearDown(controller1.dispose); final AnimationController controller2 = AnimationController( duration: const Duration(milliseconds: 600), vsync: const TestVSync(), ); + addTearDown(controller2.dispose); final AnimationController controller3 = AnimationController( duration: const Duration(milliseconds: 300), vsync: const TestVSync(), ); + addTearDown(controller3.dispose); final List log = []; Future runTest() async { log.add('a'); // t=0 @@ -62,14 +65,17 @@ void main() { duration: const Duration(milliseconds: 100), vsync: const TestVSync(), ); + addTearDown(controller1.dispose); final AnimationController controller2 = AnimationController( duration: const Duration(milliseconds: 600), vsync: const TestVSync(), ); + addTearDown(controller2.dispose); final AnimationController controller3 = AnimationController( duration: const Duration(milliseconds: 300), vsync: const TestVSync(), ); + addTearDown(controller3.dispose); final List log = []; Future runTest() async { log.add('a'); // t=0 @@ -139,6 +145,7 @@ void main() { duration: const Duration(milliseconds: 100), vsync: const TestVSync(), ); + addTearDown(controller1.dispose); final TickerFuture f = controller1.forward(); await tester.pump(); // start ticker await tester.pump(const Duration(milliseconds: 200)); // end ticker @@ -152,6 +159,7 @@ void main() { duration: const Duration(milliseconds: 100), vsync: const TestVSync(), ); + addTearDown(controller1.dispose); final TickerFuture f = controller1.forward(); await tester.pump(); // start ticker controller1.stop(); // cancel ticker @@ -169,6 +177,7 @@ void main() { duration: const Duration(milliseconds: 100), vsync: const TestVSync(), ); + addTearDown(controller1.dispose); final TickerFuture f = controller1.forward(); await tester.pump(); // start ticker await tester.pump(const Duration(milliseconds: 200)); // end ticker diff --git a/packages/flutter/test/animation/iteration_patterns_test.dart b/packages/flutter/test/animation/iteration_patterns_test.dart index 0705333d3f..d8bcea8491 100644 --- a/packages/flutter/test/animation/iteration_patterns_test.dart +++ b/packages/flutter/test/animation/iteration_patterns_test.dart @@ -85,6 +85,7 @@ void main() { duration: const Duration(milliseconds: 100), vsync: const TestVSync(), ); + addTearDown(controller.dispose); final List log = []; void listener1() { log.add('listener1'); } diff --git a/packages/flutter/test/flutter_test_config.dart b/packages/flutter/test/flutter_test_config.dart index 50c01b2e93..c3338ac720 100644 --- a/packages/flutter/test/flutter_test_config.dart +++ b/packages/flutter/test/flutter_test_config.dart @@ -25,7 +25,15 @@ Future testExecutable(FutureOr Function() testMain) { WidgetController.hitTestWarningShouldBeFatal = true; LeakTracking.warnForUnsupportedPlatforms = false; - LeakTesting.settings = LeakTesting.settings.withTrackedAll().withIgnored(allNotGCed: true); + + // TODO(polina-c): clean up leaks and stop ignoring them. + // https://github.com/flutter/flutter/issues/137311 + LeakTesting.settings = LeakTesting + .settings + .withTrackedAll() + .withIgnored( + allNotGCed: true, + ); // Enable golden file testing using Skia Gold. return flutter_goldens.testExecutable(testMain); diff --git a/packages/flutter/test/material/bottom_sheet_test.dart b/packages/flutter/test/material/bottom_sheet_test.dart index 7212498e5a..183c2aa600 100644 --- a/packages/flutter/test/material/bottom_sheet_test.dart +++ b/packages/flutter/test/material/bottom_sheet_test.dart @@ -1345,6 +1345,13 @@ void main() { testWidgetsWithLeakTracking('Verify showModalBottomSheet use AnimationController if provided.', (WidgetTester tester) async { const Key tapTarget = Key('tap-target'); + final AnimationController controller = AnimationController( + vsync: const TestVSync(), + duration: const Duration(seconds: 2), + reverseDuration: const Duration(seconds: 2), + ); + addTearDown(controller.dispose); + await tester.pumpWidget(MaterialApp( home: Scaffold( body: Builder( @@ -1355,11 +1362,7 @@ void main() { showModalBottomSheet( context: context, // The default duration and reverseDuration is 1 second - transitionAnimationController: AnimationController( - vsync: const TestVSync(), - duration: const Duration(seconds: 2), - reverseDuration: const Duration(seconds: 2), - ), + transitionAnimationController: controller, builder: (BuildContext context) { return const Text('BottomSheet'); }, @@ -1465,6 +1468,13 @@ void main() { testWidgetsWithLeakTracking('Verify persistence BottomSheet use AnimationController if provided.', (WidgetTester tester) async { const Key tapTarget = Key('tap-target'); const Key tapTargetToClose = Key('tap-target-to-close'); + final AnimationController controller = AnimationController( + vsync: const TestVSync(), + duration: const Duration(seconds: 2), + reverseDuration: const Duration(seconds: 2), + ); + addTearDown(controller.dispose); + await tester.pumpWidget(MaterialApp( home: Scaffold( body: Builder( @@ -1475,11 +1485,7 @@ void main() { showBottomSheet( context: context, // The default duration and reverseDuration is 1 second - transitionAnimationController: AnimationController( - vsync: const TestVSync(), - duration: const Duration(seconds: 2), - reverseDuration: const Duration(seconds: 2), - ), + transitionAnimationController: controller, builder: (BuildContext context) { return ElevatedButton( key: tapTargetToClose, diff --git a/packages/flutter/test/material/refresh_indicator_test.dart b/packages/flutter/test/material/refresh_indicator_test.dart index e3c1bd8933..25cd1bc107 100644 --- a/packages/flutter/test/material/refresh_indicator_test.dart +++ b/packages/flutter/test/material/refresh_indicator_test.dart @@ -1083,6 +1083,7 @@ void main() { Future testColor(Color color) async { final AnimationController positionController = AnimationController(vsync: const TestVSync()); + addTearDown(positionController.dispose); // Correspond to [_setupColorTween]. final Animation valueColorAnimation = positionController.drive( ColorTween( diff --git a/packages/flutter/test/widgets/animated_opacity_repaint_test.dart b/packages/flutter/test/widgets/animated_opacity_repaint_test.dart index bc9f446538..24704cdab2 100644 --- a/packages/flutter/test/widgets/animated_opacity_repaint_test.dart +++ b/packages/flutter/test/widgets/animated_opacity_repaint_test.dart @@ -11,6 +11,7 @@ void main() { testWidgetsWithLeakTracking('RenderAnimatedOpacityMixin does not drop layer when animating to 1', (WidgetTester tester) async { RenderTestObject.paintCount = 0; final AnimationController controller = AnimationController(vsync: const TestVSync(), duration: const Duration(seconds: 1)); + addTearDown(controller.dispose); final Tween opacityTween = Tween(begin: 0, end: 1); await tester.pumpWidget( ColoredBox( @@ -44,6 +45,7 @@ void main() { testWidgetsWithLeakTracking('RenderAnimatedOpacityMixin avoids repainting child as it animates', (WidgetTester tester) async { RenderTestObject.paintCount = 0; final AnimationController controller = AnimationController(vsync: const TestVSync(), duration: const Duration(seconds: 1)); + addTearDown(controller.dispose); final Tween opacityTween = Tween(begin: 0, end: 0.99); // Layer is dropped at 1 await tester.pumpWidget( ColoredBox( @@ -77,9 +79,8 @@ void main() { testWidgetsWithLeakTracking('RenderAnimatedOpacityMixin allows opacity layer to be disposed when animating to 0 opacity', (WidgetTester tester) async { RenderTestObject.paintCount = 0; final AnimationController controller = AnimationController(vsync: const TestVSync(), duration: const Duration(seconds: 1)); - final Tween opacityTween = Tween(begin: 0.99, end: 0); - addTearDown(controller.dispose); + final Tween opacityTween = Tween(begin: 0.99, end: 0); await tester.pumpWidget( ColoredBox( diff --git a/packages/flutter/test/widgets/fade_transition_test.dart b/packages/flutter/test/widgets/fade_transition_test.dart index e35013867e..2e07c58d3f 100644 --- a/packages/flutter/test/widgets/fade_transition_test.dart +++ b/packages/flutter/test/widgets/fade_transition_test.dart @@ -19,6 +19,7 @@ void main() { vsync: const TestVSync(), duration: const Duration(seconds: 2), ); + addTearDown(controller.dispose); await tester.pumpWidget(FadeTransition( opacity: controller, child: const Placeholder(), diff --git a/packages/flutter/test/widgets/list_view_misc_test.dart b/packages/flutter/test/widgets/list_view_misc_test.dart index c58b7a2316..3d7a4a1bd6 100644 --- a/packages/flutter/test/widgets/list_view_misc_test.dart +++ b/packages/flutter/test/widgets/list_view_misc_test.dart @@ -169,6 +169,7 @@ void main() { vsync: const TestVSync(), duration: const Duration(milliseconds: 200), ); + addTearDown(controller.dispose); // The overall height of the frame is (as ever) 600 Widget buildFrame() { diff --git a/packages/flutter/test/widgets/magnifier_test.dart b/packages/flutter/test/widgets/magnifier_test.dart index 2175efaf8e..4cae88b19f 100644 --- a/packages/flutter/test/widgets/magnifier_test.dart +++ b/packages/flutter/test/widgets/magnifier_test.dart @@ -254,6 +254,7 @@ void main() { await runFakeAsync((FakeAsync async) async { final _MockAnimationController animationController = _MockAnimationController(); + addTearDown(animationController.dispose); const RawMagnifier testMagnifier = RawMagnifier( size: Size(100, 100), diff --git a/packages/flutter/test/widgets/status_transitions_test.dart b/packages/flutter/test/widgets/status_transitions_test.dart index 0667398c26..c12fcd8f17 100644 --- a/packages/flutter/test/widgets/status_transitions_test.dart +++ b/packages/flutter/test/widgets/status_transitions_test.dart @@ -64,6 +64,7 @@ void main() { duration: const Duration(seconds: 1), vsync: const TestVSync(), ); + addTearDown(anotherController.dispose); await tester.pumpWidget(TestStatusTransitionWidget( animation: anotherController, diff --git a/packages/flutter/test/widgets/ticker_provider_test.dart b/packages/flutter/test/widgets/ticker_provider_test.dart index 1c65f075d7..1f73c0bcff 100644 --- a/packages/flutter/test/widgets/ticker_provider_test.dart +++ b/packages/flutter/test/widgets/ticker_provider_test.dart @@ -97,7 +97,7 @@ void main() { )); }); - testWidgetsWithLeakTracking('SingleTickerProviderStateMixin dispose while active', (WidgetTester tester) async { + testWidgets('SingleTickerProviderStateMixin dispose while active', (WidgetTester tester) async { final GlobalKey<_SingleTickerTestState> key = GlobalKey<_SingleTickerTestState>(); final Widget widget = _SingleTickerTest(key: key); await tester.pumpWidget(widget); @@ -137,7 +137,7 @@ void main() { } }); - testWidgetsWithLeakTracking('SingleTickerProviderStateMixin dispose while active', (WidgetTester tester) async { + testWidgets('SingleTickerProviderStateMixin dispose while active', (WidgetTester tester) async { final GlobalKey<_SingleTickerTestState> key = GlobalKey<_SingleTickerTestState>(); final Widget widget = _SingleTickerTest(key: key); await tester.pumpWidget(widget); @@ -177,7 +177,7 @@ void main() { } }); - testWidgetsWithLeakTracking('TickerProviderStateMixin dispose while any ticker is active', (WidgetTester tester) async { + testWidgets('TickerProviderStateMixin dispose while any ticker is active', (WidgetTester tester) async { final GlobalKey<_MultipleTickerTestState> key = GlobalKey<_MultipleTickerTestState>(); final Widget widget = _MultipleTickerTest(key: key); await tester.pumpWidget(widget); @@ -217,12 +217,12 @@ void main() { }); }); - testWidgetsWithLeakTracking('SingleTickerProviderStateMixin does not call State.toString', (WidgetTester tester) async { + testWidgets('SingleTickerProviderStateMixin does not call State.toString', (WidgetTester tester) async { await tester.pumpWidget(const _SingleTickerTest()); expect(tester.state<_SingleTickerTestState>(find.byType(_SingleTickerTest)).toStringCount, 0); }); - testWidgetsWithLeakTracking('TickerProviderStateMixin does not call State.toString', (WidgetTester tester) async { + testWidgets('TickerProviderStateMixin does not call State.toString', (WidgetTester tester) async { await tester.pumpWidget(const _MultipleTickerTest()); expect(tester.state<_MultipleTickerTestState>(find.byType(_MultipleTickerTest)).toStringCount, 0); }); diff --git a/packages/flutter/test/widgets/transitions_test.dart b/packages/flutter/test/widgets/transitions_test.dart index f7c8eb1726..fa2017919f 100644 --- a/packages/flutter/test/widgets/transitions_test.dart +++ b/packages/flutter/test/widgets/transitions_test.dart @@ -147,6 +147,7 @@ void main() { testWidgetsWithLeakTracking('AlignTransition animates', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation alignmentTween = AlignmentTween( begin: Alignment.centerLeft, end: Alignment.bottomRight, @@ -171,6 +172,7 @@ void main() { testWidgetsWithLeakTracking('RelativePositionedTransition animates', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation rectTween = RectTween( begin: const Rect.fromLTWH(0, 0, 30, 40), end: const Rect.fromLTWH(100, 200, 100, 200), @@ -217,6 +219,7 @@ void main() { testWidgetsWithLeakTracking('AlignTransition keeps width and height factors', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation alignmentTween = AlignmentTween( begin: Alignment.centerLeft, end: Alignment.bottomRight, @@ -238,6 +241,7 @@ void main() { testWidgetsWithLeakTracking('SizeTransition clamps negative size factors - vertical axis', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation animation = Tween(begin: -1.0, end: 1.0).animate(controller); final Widget widget = Directionality( @@ -273,6 +277,7 @@ void main() { testWidgetsWithLeakTracking('SizeTransition clamps negative size factors - horizontal axis', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation animation = Tween(begin: -1.0, end: 1.0).animate(controller); final Widget widget = Directionality( @@ -309,6 +314,7 @@ void main() { testWidgetsWithLeakTracking('SizeTransition with fixedCrossAxisSizeFactor should size its cross axis from its children - vertical axis', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation animation = Tween(begin: 0, end: 1.0).animate(controller); const Key key = Key('key'); @@ -367,6 +373,7 @@ void main() { testWidgetsWithLeakTracking('SizeTransition with fixedCrossAxisSizeFactor should size its cross axis from its children - horizontal axis', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation animation = Tween(begin: 0.0, end: 1.0).animate(controller); const Key key = Key('key'); @@ -426,6 +433,7 @@ void main() { testWidgetsWithLeakTracking('MatrixTransition animates', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Widget widget = MatrixTransition( alignment: Alignment.topRight, onTransform: (double value) => Matrix4.translationValues(value, value, value), @@ -466,6 +474,7 @@ void main() { testWidgetsWithLeakTracking('MatrixTransition maintains chosen alignment during animation', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Widget widget = MatrixTransition( alignment: Alignment.topRight, onTransform: (double value) => Matrix4.identity(), @@ -487,6 +496,7 @@ void main() { testWidgetsWithLeakTracking('RotationTransition animates', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Widget widget = RotationTransition( alignment: Alignment.topRight, turns: controller, @@ -526,6 +536,7 @@ void main() { testWidgetsWithLeakTracking('RotationTransition maintains chosen alignment during animation', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Widget widget = RotationTransition( alignment: Alignment.topRight, turns: controller, @@ -556,6 +567,7 @@ void main() { } testWidgetsWithLeakTracking('animates', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation animation = Tween(begin: 0.0, end: 1.0).animate(controller); final Widget widget = Directionality( textDirection: TextDirection.ltr, @@ -599,6 +611,7 @@ void main() { } testWidgetsWithLeakTracking('animates', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation animation = Tween(begin: 0.0, end: 1.0).animate(controller); final Widget widget = Localizations( locale: const Locale('en', 'us'), @@ -649,6 +662,7 @@ void main() { group('MatrixTransition', () { testWidgetsWithLeakTracking('uses ImageFilter when provided with FilterQuality argument', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation animation = Tween(begin: 0.0, end: 1.0).animate(controller); final Widget widget = Directionality( textDirection: TextDirection.ltr, @@ -712,6 +726,7 @@ void main() { group('ScaleTransition', () { testWidgetsWithLeakTracking('uses ImageFilter when provided with FilterQuality argument', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation animation = Tween(begin: 0.0, end: 1.0).animate(controller); final Widget widget = Directionality( textDirection: TextDirection.ltr, @@ -765,6 +780,7 @@ void main() { group('RotationTransition', () { testWidgetsWithLeakTracking('uses ImageFilter when provided with FilterQuality argument', (WidgetTester tester) async { final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); final Animation animation = Tween(begin: 0.0, end: 1.0).animate(controller); final Widget widget = Directionality( textDirection: TextDirection.ltr,