From 0099d1a96ac80babc5b85cc7c7ca6764091b75f3 Mon Sep 17 00:00:00 2001 From: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:52:18 +0800 Subject: [PATCH] test: Fix memory leak in transitions test (#146747) --- .../test/widgets/transitions_test.dart | 88 ++++++++++--------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/packages/flutter/test/widgets/transitions_test.dart b/packages/flutter/test/widgets/transitions_test.dart index f1b39b50965..984638951e5 100644 --- a/packages/flutter/test/widgets/transitions_test.dart +++ b/packages/flutter/test/widgets/transitions_test.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; void main() { testWidgets('toString control test', (WidgetTester tester) async { @@ -95,53 +96,60 @@ void main() { expect(actualDecoration.boxShadow, null); }); - testWidgets('animations work with curves test', (WidgetTester tester) async { - final Animation curvedDecorationAnimation = - decorationTween.animate(CurvedAnimation( - parent: controller, - curve: Curves.easeOut, - )); + testWidgets( + 'animations work with curves test', + // TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in] + experimentalLeakTesting: LeakTesting.settings.withTracked(classes: const ['CurvedAnimation']), + (WidgetTester tester) async { + final CurvedAnimation animation = CurvedAnimation( + parent: controller, + curve: Curves.easeOut, + ); + addTearDown(animation.dispose); + final Animation curvedDecorationAnimation = + decorationTween.animate(animation); - final DecoratedBoxTransition transitionUnderTest = DecoratedBoxTransition( - decoration: curvedDecorationAnimation, - position: DecorationPosition.foreground, - child: const Text( - "Doesn't matter", - textDirection: TextDirection.ltr, - ), - ); + final DecoratedBoxTransition transitionUnderTest = DecoratedBoxTransition( + decoration: curvedDecorationAnimation, + position: DecorationPosition.foreground, + child: const Text( + "Doesn't matter", + textDirection: TextDirection.ltr, + ), + ); - await tester.pumpWidget(transitionUnderTest); + await tester.pumpWidget(transitionUnderTest); - RenderDecoratedBox actualBox = tester.renderObject(find.byType(DecoratedBox)); - BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration; + RenderDecoratedBox actualBox = tester.renderObject(find.byType(DecoratedBox)); + BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration; - expect(actualDecoration.color, const Color(0xFFFFFFFF)); - expect(actualDecoration.boxShadow![0].blurRadius, 10.0); - expect(actualDecoration.boxShadow![0].spreadRadius, 4.0); - expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); + expect(actualDecoration.color, const Color(0xFFFFFFFF)); + expect(actualDecoration.boxShadow![0].blurRadius, 10.0); + expect(actualDecoration.boxShadow![0].spreadRadius, 4.0); + expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); - controller.value = 0.5; + controller.value = 0.5; - await tester.pump(); - actualBox = tester.renderObject(find.byType(DecoratedBox)); - actualDecoration = actualBox.decoration as BoxDecoration; + await tester.pump(); + actualBox = tester.renderObject(find.byType(DecoratedBox)); + actualDecoration = actualBox.decoration as BoxDecoration; - // Same as the test above but the values should be much closer to the - // tween's end values given the easeOut curve. - expect(actualDecoration.color, const Color(0xFF505050)); - expect(actualDecoration.border, isA()); - final Border border = actualDecoration.border! as Border; - expect(border.left.width, moreOrLessEquals(1.9, epsilon: 0.1)); - expect(border.left.style, BorderStyle.solid); - expect(border.left.color, const Color(0xFF151515)); - expect(actualDecoration.borderRadius!.resolve(TextDirection.ltr).topLeft.x, moreOrLessEquals(6.8, epsilon: 0.1)); - expect(actualDecoration.shape, BoxShape.rectangle); - expect(actualDecoration.boxShadow![0].blurRadius, moreOrLessEquals(3.1, epsilon: 0.1)); - expect(actualDecoration.boxShadow![0].spreadRadius, moreOrLessEquals(1.2, epsilon: 0.1)); - // Scaling a shadow doesn't change the color. - expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); - }); + // Same as the test above but the values should be much closer to the + // tween's end values given the easeOut curve. + expect(actualDecoration.color, const Color(0xFF505050)); + expect(actualDecoration.border, isA()); + final Border border = actualDecoration.border! as Border; + expect(border.left.width, moreOrLessEquals(1.9, epsilon: 0.1)); + expect(border.left.style, BorderStyle.solid); + expect(border.left.color, const Color(0xFF151515)); + expect(actualDecoration.borderRadius!.resolve(TextDirection.ltr).topLeft.x, moreOrLessEquals(6.8, epsilon: 0.1)); + expect(actualDecoration.shape, BoxShape.rectangle); + expect(actualDecoration.boxShadow![0].blurRadius, moreOrLessEquals(3.1, epsilon: 0.1)); + expect(actualDecoration.boxShadow![0].spreadRadius, moreOrLessEquals(1.2, epsilon: 0.1)); + // Scaling a shadow doesn't change the color. + expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); + }, + ); }); testWidgets('AlignTransition animates', (WidgetTester tester) async {