@@ -15,6 +15,7 @@ void main() {
15
15
double minChildSize = .25 ,
16
16
bool snap = false ,
17
17
List <double >? snapSizes,
18
+ Duration ? snapAnimationDuration,
18
19
double ? itemExtent,
19
20
Key ? containerKey,
20
21
Key ? stackKey,
@@ -40,6 +41,7 @@ void main() {
40
41
initialChildSize: initialChildSize,
41
42
snap: snap,
42
43
snapSizes: snapSizes,
44
+ snapAnimationDuration: snapAnimationDuration,
43
45
builder: (BuildContext context, ScrollController scrollController) {
44
46
return NotificationListener <ScrollNotification >(
45
47
onNotification: onScrollNotification,
@@ -485,58 +487,64 @@ void main() {
485
487
});
486
488
}
487
489
488
- testWidgets ('Zero velocity drag snaps to nearest snap target' , (WidgetTester tester) async {
489
- const Key stackKey = ValueKey <String >('stack' );
490
- const Key containerKey = ValueKey <String >('container' );
491
- await tester.pumpWidget (boilerplateWidget (null ,
492
- snap: true ,
493
- stackKey: stackKey,
494
- containerKey: containerKey,
495
- snapSizes: < double > [.25 , .5 , .75 , 1.0 ],
496
- ));
497
- await tester.pumpAndSettle ();
498
- final double screenHeight = tester.getSize (find.byKey (stackKey)).height;
490
+ for (final Duration ? snapAnimationDuration in < Duration ? > [null , const Duration (seconds: 2 )]) {
491
+ testWidgets (
492
+ 'Zero velocity drag snaps to nearest snap target with '
493
+ 'snapAnimationDuration: $snapAnimationDuration ' ,
494
+ (WidgetTester tester) async {
495
+ const Key stackKey = ValueKey <String >('stack' );
496
+ const Key containerKey = ValueKey <String >('container' );
497
+ await tester.pumpWidget (boilerplateWidget (null ,
498
+ snap: true ,
499
+ stackKey: stackKey,
500
+ containerKey: containerKey,
501
+ snapSizes: < double > [.25 , .5 , .75 , 1.0 ],
502
+ snapAnimationDuration: snapAnimationDuration
503
+ ));
504
+ await tester.pumpAndSettle ();
505
+ final double screenHeight = tester.getSize (find.byKey (stackKey)).height;
499
506
500
- // We are dragging up, but we'll snap down because we're closer to .75 than 1.
501
- await tester.drag (find.text ('Item 1' ), Offset (0 , - .35 * screenHeight));
502
- await tester.pumpAndSettle ();
503
- expect (
504
- tester.getSize (find.byKey (containerKey)).height / screenHeight,
505
- closeTo (.75 , precisionErrorTolerance),
506
- );
507
+ // We are dragging up, but we'll snap down because we're closer to .75 than 1.
508
+ await tester.drag (find.text ('Item 1' ), Offset (0 , - .35 * screenHeight));
509
+ await tester.pumpAndSettle ();
510
+ expect (
511
+ tester.getSize (find.byKey (containerKey)).height / screenHeight,
512
+ closeTo (.75 , precisionErrorTolerance),
513
+ );
507
514
508
- // Drag up and snap up.
509
- await tester.drag (find.text ('Item 1' ), Offset (0 , - .2 * screenHeight));
510
- await tester.pumpAndSettle ();
511
- expect (
512
- tester.getSize (find.byKey (containerKey)).height / screenHeight,
513
- closeTo (1.0 , precisionErrorTolerance),
514
- );
515
+ // Drag up and snap up.
516
+ await tester.drag (find.text ('Item 1' ), Offset (0 , - .2 * screenHeight));
517
+ await tester.pumpAndSettle ();
518
+ expect (
519
+ tester.getSize (find.byKey (containerKey)).height / screenHeight,
520
+ closeTo (1.0 , precisionErrorTolerance),
521
+ );
515
522
516
- // Drag down and snap up.
517
- await tester.drag (find.text ('Item 1' ), Offset (0 , .1 * screenHeight));
518
- await tester.pumpAndSettle ();
519
- expect (
520
- tester.getSize (find.byKey (containerKey)).height / screenHeight,
521
- closeTo (1.0 , precisionErrorTolerance),
522
- );
523
+ // Drag down and snap up.
524
+ await tester.drag (find.text ('Item 1' ), Offset (0 , .1 * screenHeight));
525
+ await tester.pumpAndSettle ();
526
+ expect (
527
+ tester.getSize (find.byKey (containerKey)).height / screenHeight,
528
+ closeTo (1.0 , precisionErrorTolerance),
529
+ );
523
530
524
- // Drag down and snap down.
525
- await tester.drag (find.text ('Item 1' ), Offset (0 , .45 * screenHeight));
526
- await tester.pumpAndSettle ();
527
- expect (
528
- tester.getSize (find.byKey (containerKey)).height / screenHeight,
529
- closeTo (.5 , precisionErrorTolerance),
530
- );
531
+ // Drag down and snap down.
532
+ await tester.drag (find.text ('Item 1' ), Offset (0 , .45 * screenHeight));
533
+ await tester.pumpAndSettle ();
534
+ expect (
535
+ tester.getSize (find.byKey (containerKey)).height / screenHeight,
536
+ closeTo (.5 , precisionErrorTolerance),
537
+ );
531
538
532
- // Fling up with negligible velocity and snap down.
533
- await tester.fling (find.text ('Item 1' ), Offset (0 , .1 * screenHeight), 1 );
534
- await tester.pumpAndSettle ();
535
- expect (
536
- tester.getSize (find.byKey (containerKey)).height / screenHeight,
537
- closeTo (.5 , precisionErrorTolerance),
538
- );
539
- }, variant: TargetPlatformVariant .all ());
539
+ // Fling up with negligible velocity and snap down.
540
+ await tester.fling (find.text ('Item 1' ), Offset (0 , .1 * screenHeight), 1 );
541
+ await tester.pumpAndSettle ();
542
+ expect (
543
+ tester.getSize (find.byKey (containerKey)).height / screenHeight,
544
+ closeTo (.5 , precisionErrorTolerance),
545
+ );
546
+ }, variant: TargetPlatformVariant .all ());
547
+ }
540
548
541
549
for (final List <double >? snapSizes in < List <double >? > [null , < double > []]) {
542
550
testWidgets ('Setting snapSizes to $snapSizes resolves to min and max' , (WidgetTester tester) async {
0 commit comments