mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
test: Fix memory leak in transitions test (#146747)
This commit is contained in:
parent
63634c25ad
commit
0099d1a96a
@ -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<Decoration> 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 <String>['CurvedAnimation']),
|
||||
(WidgetTester tester) async {
|
||||
final CurvedAnimation animation = CurvedAnimation(
|
||||
parent: controller,
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
addTearDown(animation.dispose);
|
||||
final Animation<Decoration> 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<Border>());
|
||||
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<Border>());
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user