@@ -120,11 +120,13 @@ void main() {
120120 testWidgets (
121121 'slot layout properly switches between items with the appropriate animation' ,
122122 (WidgetTester tester) async {
123- await tester.pumpWidget (slot (300 , tester));
123+ await tester
124+ .pumpWidget (slot (300 , const Duration (milliseconds: 1000 ), tester));
124125 expect (begin, findsOneWidget);
125126 expect (end, findsNothing);
126127
127- await tester.pumpWidget (slot (500 , tester));
128+ await tester
129+ .pumpWidget (slot (500 , const Duration (milliseconds: 1000 ), tester));
128130 await tester.pump ();
129131 await tester.pump (const Duration (milliseconds: 500 ));
130132 expect (tester.widget <SlideTransition >(slideOut ('0' )).position.value,
@@ -146,7 +148,7 @@ void main() {
146148 testWidgets ('AnimatedSwitcher does not spawn duplicate keys on rapid resize' ,
147149 (WidgetTester tester) async {
148150 // Populate the smaller slot layout and let the animation settle.
149- await tester.pumpWidget (slot (300 , tester));
151+ await tester.pumpWidget (slot (300 , const Duration (seconds : 1 ), tester));
150152 await tester.pumpAndSettle ();
151153 expect (begin, findsOneWidget);
152154 expect (end, findsNothing);
@@ -157,12 +159,12 @@ void main() {
157159 for (int i = 0 ; i < 2 ; i++ ) {
158160 // Resize between the two slot layouts, but do not pump the animation
159161 // until completion.
160- await tester.pumpWidget (slot (500 , tester));
162+ await tester.pumpWidget (slot (500 , const Duration (seconds : 1 ), tester));
161163 await tester.pump (const Duration (milliseconds: 100 ));
162164 expect (begin, findsOneWidget);
163165 expect (end, findsOneWidget);
164166
165- await tester.pumpWidget (slot (300 , tester));
167+ await tester.pumpWidget (slot (300 , const Duration (seconds : 1 ), tester));
166168 await tester.pump (const Duration (milliseconds: 100 ));
167169 expect (begin, findsOneWidget);
168170 expect (end, findsOneWidget);
@@ -171,18 +173,18 @@ void main() {
171173
172174 testWidgets ('slot layout can tolerate rapid changes in breakpoints' ,
173175 (WidgetTester tester) async {
174- await tester.pumpWidget (slot (300 , tester));
176+ await tester.pumpWidget (slot (300 , const Duration (seconds : 1 ), tester));
175177 expect (begin, findsOneWidget);
176178 expect (end, findsNothing);
177179
178- await tester.pumpWidget (slot (500 , tester));
180+ await tester.pumpWidget (slot (500 , const Duration (seconds : 1 ), tester));
179181 await tester.pump ();
180182 await tester.pump (const Duration (milliseconds: 100 ));
181183 expect (tester.widget <SlideTransition >(slideOut ('0' )).position.value,
182184 offsetMoreOrLessEquals (const Offset (- 0.1 , 0 ), epsilon: 0.05 ));
183185 expect (tester.widget <SlideTransition >(slideIn ('400' )).position.value,
184186 offsetMoreOrLessEquals (const Offset (- 0.9 , 0 ), epsilon: 0.05 ));
185- await tester.pumpWidget (slot (300 , tester));
187+ await tester.pumpWidget (slot (300 , const Duration (seconds : 1 ), tester));
186188 await tester.pumpAndSettle ();
187189 expect (begin, findsOneWidget);
188190 expect (end, findsNothing);
@@ -243,11 +245,35 @@ void main() {
243245 tester.getBottomRight (secondaryTestBreakpoint), const Offset (390 , 790 ));
244246 });
245247
248+ testWidgets ('adaptive layout can adjust animation duration' ,
249+ (WidgetTester tester) async {
250+ // Populate the smaller slot layout and let the animation settle.
251+ await tester
252+ .pumpWidget (slot (300 , const Duration (milliseconds: 100 ), tester));
253+ await tester.pumpAndSettle ();
254+ expect (begin, findsOneWidget);
255+ expect (end, findsNothing);
256+
257+ // expand in 1/5 second.
258+ await tester
259+ .pumpWidget (slot (500 , const Duration (milliseconds: 200 ), tester));
260+
261+ // after 100ms, we expect both widgets to be present.
262+ await tester.pump (const Duration (milliseconds: 50 ));
263+ expect (begin, findsOneWidget);
264+ expect (end, findsOneWidget);
265+
266+ // After 1/5 second, all animations should be done.
267+ await tester.pump (const Duration (milliseconds: 200 ));
268+ expect (begin, findsNothing);
269+ expect (end, findsOneWidget);
270+
271+ await tester.pumpAndSettle ();
272+ });
273+
246274 testWidgets ('adaptive layout does not animate when animations off' ,
247275 (WidgetTester tester) async {
248276 final Finder testBreakpoint = find.byKey (const Key ('Test Breakpoint' ));
249- final Finder secondaryTestBreakpoint =
250- find.byKey (const Key ('Secondary Test Breakpoint' ));
251277
252278 await tester.pumpWidget (
253279 await layout (width: 400 , tester: tester, animations: false ));
@@ -257,9 +283,6 @@ void main() {
257283
258284 expect (tester.getTopLeft (testBreakpoint), const Offset (10 , 10 ));
259285 expect (tester.getBottomRight (testBreakpoint), const Offset (200 , 790 ));
260- expect (tester.getTopLeft (secondaryTestBreakpoint), const Offset (200 , 10 ));
261- expect (
262- tester.getBottomRight (secondaryTestBreakpoint), const Offset (390 , 790 ));
263286 });
264287}
265288
@@ -306,6 +329,7 @@ Future<MediaQuery> layout({
306329 TextDirection directionality = TextDirection .ltr,
307330 double ? bodyRatio,
308331 bool animations = true ,
332+ int durationMs = 1000 ,
309333}) async {
310334 await tester.binding.setSurfaceSize (Size (width, 800 ));
311335 return MediaQuery (
@@ -415,7 +439,7 @@ AnimatedWidget leftInOut(Widget child, Animation<double> animation) {
415439 );
416440}
417441
418- MediaQuery slot (double width, WidgetTester tester) {
442+ MediaQuery slot (double width, Duration duration, WidgetTester tester) {
419443 return MediaQuery (
420444 data: MediaQueryData .fromView (tester.view).copyWith (size: Size (width, 800 )),
421445 child: Directionality (
@@ -425,12 +449,14 @@ MediaQuery slot(double width, WidgetTester tester) {
425449 TestBreakpoint0 (): SlotLayout .from (
426450 inAnimation: leftOutIn,
427451 outAnimation: leftInOut,
452+ duration: duration,
428453 key: const Key ('0' ),
429454 builder: (_) => const SizedBox (width: 10 , height: 10 ),
430455 ),
431456 TestBreakpoint400 (): SlotLayout .from (
432457 inAnimation: leftOutIn,
433458 outAnimation: leftInOut,
459+ duration: duration,
434460 key: const Key ('400' ),
435461 builder: (_) => const SizedBox (width: 10 , height: 10 ),
436462 ),
0 commit comments