Skip to content

Commit 3701d0d

Browse files
committed
Refactor Hero widget tests for customizable animation curves
- Removed unnecessary UniqueKey from MaterialApp in tests. - Simplified the test structure for customizable hero animation curves by using inline lists instead of separate variables. - Enhanced test descriptions to clarify the specific curves being tested for both normal and reversed animations. - Ensured consistency in testing the behavior of the Hero widget with various animation curves.
1 parent ac959f9 commit 3701d0d

1 file changed

Lines changed: 33 additions & 41 deletions

File tree

‎packages/flutter/test/widgets/heroes_test.dart‎

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Future<void> verifyPoppedHeroCurve({
3636

3737
await tester.pumpWidget(
3838
MaterialApp(
39-
key: UniqueKey(),
4039
navigatorKey: navigator,
4140
navigatorObservers: <NavigatorObserver>[observer],
4241
home: Scaffold(
@@ -772,20 +771,17 @@ Future<void> main() async {
772771
);
773772
});
774773

775-
testWidgets('Heroes animation curve is customizable', (WidgetTester tester) async {
776-
final testCurvesList = <Curve>[
777-
Curves.linear,
778-
Curves.ease,
779-
Curves.linearToEaseOut,
780-
Curves.easeInOutCubicEmphasized,
781-
Curves.fastOutSlowIn,
782-
];
783-
784-
for (final curve in testCurvesList) {
774+
for (final curve in <Curve>[
775+
Curves.linear,
776+
Curves.ease,
777+
Curves.linearToEaseOut,
778+
Curves.easeInOutCubicEmphasized,
779+
Curves.fastOutSlowIn,
780+
]) {
781+
testWidgets('Heroes animation curve is customizable with curve=$curve', (WidgetTester tester) async {
785782
final observer = TransitionDurationObserver();
786783
await tester.pumpWidget(
787784
MaterialApp(
788-
key: UniqueKey(),
789785
navigatorObservers: <NavigatorObserver>[observer],
790786
routes: <String, WidgetBuilder>{
791787
'/': (BuildContext context) => Material(
@@ -876,8 +872,8 @@ Future<void> main() async {
876872
moreOrLessEquals(curve.transform(1.0) * deltaHeight + initialHeight, epsilon: epsilon),
877873
reason: 'curve=$curveName t=1.00 duration=$duration',
878874
);
879-
}
880-
});
875+
});
876+
}
881877

882878
testWidgets('Heroes are not interactive', (WidgetTester tester) async {
883879
final log = <String>[];
@@ -3474,36 +3470,32 @@ Future<void> main() async {
34743470
expect(heroSize, tween.transform(1.0));
34753471
});
34763472

3477-
testWidgets('popped hero curve is customizable', (WidgetTester tester) async {
3478-
final testReverseCurvesList = <Curve>[
3479-
Curves.linear,
3480-
Curves.ease,
3481-
Curves.linearToEaseOut,
3482-
Curves.easeInOutCubicEmphasized,
3483-
Curves.fastOutSlowIn,
3484-
];
3485-
3486-
for (final reverseCurve in testReverseCurvesList) {
3473+
for (final reverseCurve in <Curve>[
3474+
Curves.linear,
3475+
Curves.ease,
3476+
Curves.linearToEaseOut,
3477+
Curves.easeInOutCubicEmphasized,
3478+
Curves.fastOutSlowIn,
3479+
]) {
3480+
testWidgets('popped hero curve is customizable with reverseCurve=$reverseCurve', (WidgetTester tester) async {
34873481
await verifyPoppedHeroCurve(tester: tester, curve: Curves.linear, reverseCurve: reverseCurve);
3488-
}
3489-
});
3490-
3491-
testWidgets(
3492-
'popped hero curve is the flipped version of [curve] if reverseCurve is not specified',
3493-
(WidgetTester tester) async {
3494-
final testCurvesList = <Curve>[
3495-
Curves.linear,
3496-
Curves.ease,
3497-
Curves.linearToEaseOut,
3498-
Curves.easeInOutCubicEmphasized,
3499-
Curves.fastOutSlowIn,
3500-
];
3482+
});
3483+
}
35013484

3502-
for (final curve in testCurvesList) {
3485+
for (final curve in <Curve>[
3486+
Curves.linear,
3487+
Curves.ease,
3488+
Curves.linearToEaseOut,
3489+
Curves.easeInOutCubicEmphasized,
3490+
Curves.fastOutSlowIn,
3491+
]) {
3492+
testWidgets(
3493+
'popped hero uses flipped curve=$curve when reverseCurve is not specified',
3494+
(WidgetTester tester) async {
35033495
await verifyPoppedHeroCurve(tester: tester, curve: curve, reverseCurve: null);
3504-
}
3505-
},
3506-
);
3496+
},
3497+
);
3498+
}
35073499

35083500
testWidgets('Heroes in enabled HeroMode do transition', (WidgetTester tester) async {
35093501
await tester.pumpWidget(

0 commit comments

Comments
 (0)