@@ -120,11 +120,13 @@ void main() {
120
120
testWidgets (
121
121
'slot layout properly switches between items with the appropriate animation' ,
122
122
(WidgetTester tester) async {
123
- await tester.pumpWidget (slot (300 , tester));
123
+ await tester
124
+ .pumpWidget (slot (300 , const Duration (milliseconds: 1000 ), tester));
124
125
expect (begin, findsOneWidget);
125
126
expect (end, findsNothing);
126
127
127
- await tester.pumpWidget (slot (500 , tester));
128
+ await tester
129
+ .pumpWidget (slot (500 , const Duration (milliseconds: 1000 ), tester));
128
130
await tester.pump ();
129
131
await tester.pump (const Duration (milliseconds: 500 ));
130
132
expect (tester.widget <SlideTransition >(slideOut ('0' )).position.value,
@@ -146,7 +148,7 @@ void main() {
146
148
testWidgets ('AnimatedSwitcher does not spawn duplicate keys on rapid resize' ,
147
149
(WidgetTester tester) async {
148
150
// 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));
150
152
await tester.pumpAndSettle ();
151
153
expect (begin, findsOneWidget);
152
154
expect (end, findsNothing);
@@ -157,12 +159,12 @@ void main() {
157
159
for (int i = 0 ; i < 2 ; i++ ) {
158
160
// Resize between the two slot layouts, but do not pump the animation
159
161
// until completion.
160
- await tester.pumpWidget (slot (500 , tester));
162
+ await tester.pumpWidget (slot (500 , const Duration (seconds : 1 ), tester));
161
163
await tester.pump (const Duration (milliseconds: 100 ));
162
164
expect (begin, findsOneWidget);
163
165
expect (end, findsOneWidget);
164
166
165
- await tester.pumpWidget (slot (300 , tester));
167
+ await tester.pumpWidget (slot (300 , const Duration (seconds : 1 ), tester));
166
168
await tester.pump (const Duration (milliseconds: 100 ));
167
169
expect (begin, findsOneWidget);
168
170
expect (end, findsOneWidget);
@@ -171,18 +173,18 @@ void main() {
171
173
172
174
testWidgets ('slot layout can tolerate rapid changes in breakpoints' ,
173
175
(WidgetTester tester) async {
174
- await tester.pumpWidget (slot (300 , tester));
176
+ await tester.pumpWidget (slot (300 , const Duration (seconds : 1 ), tester));
175
177
expect (begin, findsOneWidget);
176
178
expect (end, findsNothing);
177
179
178
- await tester.pumpWidget (slot (500 , tester));
180
+ await tester.pumpWidget (slot (500 , const Duration (seconds : 1 ), tester));
179
181
await tester.pump ();
180
182
await tester.pump (const Duration (milliseconds: 100 ));
181
183
expect (tester.widget <SlideTransition >(slideOut ('0' )).position.value,
182
184
offsetMoreOrLessEquals (const Offset (- 0.1 , 0 ), epsilon: 0.05 ));
183
185
expect (tester.widget <SlideTransition >(slideIn ('400' )).position.value,
184
186
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));
186
188
await tester.pumpAndSettle ();
187
189
expect (begin, findsOneWidget);
188
190
expect (end, findsNothing);
@@ -243,11 +245,35 @@ void main() {
243
245
tester.getBottomRight (secondaryTestBreakpoint), const Offset (390 , 790 ));
244
246
});
245
247
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
+
246
274
testWidgets ('adaptive layout does not animate when animations off' ,
247
275
(WidgetTester tester) async {
248
276
final Finder testBreakpoint = find.byKey (const Key ('Test Breakpoint' ));
249
- final Finder secondaryTestBreakpoint =
250
- find.byKey (const Key ('Secondary Test Breakpoint' ));
251
277
252
278
await tester.pumpWidget (
253
279
await layout (width: 400 , tester: tester, animations: false ));
@@ -257,9 +283,6 @@ void main() {
257
283
258
284
expect (tester.getTopLeft (testBreakpoint), const Offset (10 , 10 ));
259
285
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 ));
263
286
});
264
287
}
265
288
@@ -306,6 +329,7 @@ Future<MediaQuery> layout({
306
329
TextDirection directionality = TextDirection .ltr,
307
330
double ? bodyRatio,
308
331
bool animations = true ,
332
+ int durationMs = 1000 ,
309
333
}) async {
310
334
await tester.binding.setSurfaceSize (Size (width, 800 ));
311
335
return MediaQuery (
@@ -415,7 +439,7 @@ AnimatedWidget leftInOut(Widget child, Animation<double> animation) {
415
439
);
416
440
}
417
441
418
- MediaQuery slot (double width, WidgetTester tester) {
442
+ MediaQuery slot (double width, Duration duration, WidgetTester tester) {
419
443
return MediaQuery (
420
444
data: MediaQueryData .fromView (tester.view).copyWith (size: Size (width, 800 )),
421
445
child: Directionality (
@@ -425,12 +449,14 @@ MediaQuery slot(double width, WidgetTester tester) {
425
449
TestBreakpoint0 (): SlotLayout .from (
426
450
inAnimation: leftOutIn,
427
451
outAnimation: leftInOut,
452
+ duration: duration,
428
453
key: const Key ('0' ),
429
454
builder: (_) => const SizedBox (width: 10 , height: 10 ),
430
455
),
431
456
TestBreakpoint400 (): SlotLayout .from (
432
457
inAnimation: leftOutIn,
433
458
outAnimation: leftInOut,
459
+ duration: duration,
434
460
key: const Key ('400' ),
435
461
builder: (_) => const SizedBox (width: 10 , height: 10 ),
436
462
),
0 commit comments