Skip to content

Commit 3f00bb1

Browse files
authored
[material_ui] Port routes_transition_test to material_ui (flutter#12634)
Ports routes_transition_test.dart from flutter/flutter to material_ui. The original test is removed separately in flutter#186620 and added here to preserve its Material navigation transition coverage. Part of [flutter#177414.](flutter#188444) Related to [flutter#188444.](flutter#186620) ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent bfd75ff commit 3f00bb1

1 file changed

Lines changed: 165 additions & 0 deletions

File tree

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:material_ui/material_ui.dart';
7+
8+
void main() {
9+
testWidgets('navigating with transitions of different lengths', (WidgetTester tester) async {
10+
final observer = TransitionDurationObserver();
11+
12+
await tester.pumpWidget(
13+
MaterialApp(
14+
navigatorObservers: <NavigatorObserver>[observer],
15+
onGenerateRoute: (RouteSettings settings) {
16+
return switch (settings.name) {
17+
// A route that uses the default page transition.
18+
'/' => MaterialPageRoute<void>(
19+
builder: (BuildContext context) {
20+
return Scaffold(
21+
body: Center(
22+
child: Column(
23+
children: <Widget>[
24+
const Text('Page 1'),
25+
TextButton(
26+
onPressed: () {
27+
Navigator.pushNamed(context, '/2');
28+
},
29+
child: const Text('Next'),
30+
),
31+
],
32+
),
33+
),
34+
);
35+
},
36+
),
37+
// A route that uses ZoomPageTransitionsBuilder.
38+
'/2' => _TestTransitionRoute<void>(
39+
transitionDurationOverride: const Duration(milliseconds: 456),
40+
reverseTransitionDurationOverride: const Duration(milliseconds: 567),
41+
pageTransitionsBuilder: const ZoomPageTransitionsBuilder(),
42+
builder: (BuildContext context) {
43+
return Scaffold(
44+
body: Center(
45+
child: Column(
46+
children: <Widget>[
47+
const Text('Page 2'),
48+
TextButton(
49+
onPressed: () {
50+
Navigator.pushNamed(context, '/3');
51+
},
52+
child: const Text('Next'),
53+
),
54+
TextButton(
55+
onPressed: () {
56+
Navigator.pop(context);
57+
},
58+
child: const Text('Back'),
59+
),
60+
],
61+
),
62+
),
63+
);
64+
},
65+
),
66+
// A route that uses FadeForwardsPageTransitionsBuilder.
67+
'/3' => _TestTransitionRoute<void>(
68+
pageTransitionsBuilder: const FadeForwardsPageTransitionsBuilder(),
69+
builder: (BuildContext context) {
70+
return Scaffold(
71+
body: Center(
72+
child: Column(
73+
children: <Widget>[
74+
const Text('Page 3'),
75+
TextButton(
76+
onPressed: () {
77+
Navigator.pop(context);
78+
},
79+
child: const Text('Back'),
80+
),
81+
],
82+
),
83+
),
84+
);
85+
},
86+
),
87+
_ => throw Exception('Invalid route.'),
88+
};
89+
},
90+
),
91+
);
92+
93+
expect(find.text('Page 1'), findsOneWidget);
94+
expect(find.text('Page 2'), findsNothing);
95+
expect(find.text('Page 3'), findsNothing);
96+
97+
await tester.tap(find.text('Next'));
98+
99+
await observer.pumpPastTransition(tester);
100+
101+
expect(find.text('Page 1'), findsNothing);
102+
expect(find.text('Page 2'), findsOneWidget);
103+
expect(find.text('Page 3'), findsNothing);
104+
105+
await tester.tap(find.text('Next'));
106+
107+
await observer.pumpPastTransition(tester);
108+
109+
expect(find.text('Page 1'), findsNothing);
110+
expect(find.text('Page 2'), findsNothing);
111+
expect(find.text('Page 3'), findsOneWidget);
112+
113+
await tester.tap(find.text('Back'));
114+
115+
await observer.pumpPastTransition(tester);
116+
117+
expect(find.text('Page 1'), findsNothing);
118+
expect(find.text('Page 2'), findsOneWidget);
119+
expect(find.text('Page 3'), findsNothing);
120+
121+
await tester.tap(find.text('Back'));
122+
123+
await observer.pumpPastTransition(tester);
124+
125+
expect(find.text('Page 1'), findsOneWidget);
126+
expect(find.text('Page 2'), findsNothing);
127+
expect(find.text('Page 3'), findsNothing);
128+
});
129+
}
130+
131+
class _TestTransitionRoute<T> extends MaterialPageRoute<T> {
132+
_TestTransitionRoute({
133+
required super.builder,
134+
required this.pageTransitionsBuilder,
135+
this.transitionDurationOverride,
136+
this.reverseTransitionDurationOverride,
137+
});
138+
139+
final PageTransitionsBuilder pageTransitionsBuilder;
140+
final Duration? transitionDurationOverride;
141+
final Duration? reverseTransitionDurationOverride;
142+
143+
@override
144+
Widget buildTransitions(
145+
BuildContext context,
146+
Animation<double> animation,
147+
Animation<double> secondaryAnimation,
148+
Widget child,
149+
) {
150+
return pageTransitionsBuilder.buildTransitions(
151+
this,
152+
context,
153+
animation,
154+
secondaryAnimation,
155+
child,
156+
);
157+
}
158+
159+
@override
160+
Duration get transitionDuration =>
161+
transitionDurationOverride ?? pageTransitionsBuilder.transitionDuration;
162+
@override
163+
Duration get reverseTransitionDuration =>
164+
reverseTransitionDurationOverride ?? pageTransitionsBuilder.reverseTransitionDuration;
165+
}

0 commit comments

Comments
 (0)