@@ -377,6 +377,272 @@ void main() {
377
377
);
378
378
});
379
379
380
+ testWidgets ('Back swipe less than halfway is interrupted by route pop' , (WidgetTester tester) async {
381
+ // Regression test for https://github.com/flutter/flutter/issues/141268
382
+ final GlobalKey scaffoldKey = GlobalKey ();
383
+
384
+ await tester.pumpWidget (
385
+ CupertinoApp (
386
+ home: CupertinoPageScaffold (
387
+ key: scaffoldKey,
388
+ child: Center (
389
+ child: Column (
390
+ children: < Widget > [
391
+ const Text ('Page 1' ),
392
+ CupertinoButton (
393
+ onPressed: () {
394
+ Navigator .push <void >(scaffoldKey.currentContext! , CupertinoPageRoute <void >(
395
+ builder: (BuildContext context) {
396
+ return const CupertinoPageScaffold (
397
+ child: Center (child: Text ('Page 2' )),
398
+ );
399
+ },
400
+ ));
401
+ },
402
+ child: const Text ('Push Page 2' ),
403
+ ),
404
+ ],
405
+ ),
406
+ ),
407
+ ),
408
+ ),
409
+ );
410
+
411
+ expect (find.text ('Page 1' ), findsOneWidget);
412
+ expect (find.text ('Page 2' ), findsNothing);
413
+
414
+ await tester.tap (find.text ('Push Page 2' ));
415
+ await tester.pumpAndSettle ();
416
+ expect (find.text ('Page 1' ), findsNothing);
417
+ expect (find.text ('Page 2' ), findsOneWidget);
418
+
419
+ // Start a back gesture and move it less than 50% across the screen.
420
+ final TestGesture gesture = await tester.startGesture (const Offset (5.0 , 300.0 ));
421
+ await gesture.moveBy (const Offset (100.0 , 0.0 ));
422
+ await tester.pump ();
423
+ expect ( // The second route has been dragged to the right.
424
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 2' ), matching: find.byType (CupertinoPageScaffold ))),
425
+ const Offset (100.0 , 0.0 ),
426
+ );
427
+ expect ( // The first route is sliding in from the left.
428
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 1' ), matching: find.byType (CupertinoPageScaffold ))).dx,
429
+ lessThan (0 ),
430
+ );
431
+
432
+ // Programmatically pop and observe that Page 2 was popped as if there were
433
+ // no back gesture.
434
+ Navigator .pop <void >(scaffoldKey.currentContext! );
435
+ await tester.pumpAndSettle ();
436
+ expect (
437
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 1' ), matching: find.byType (CupertinoPageScaffold ))),
438
+ Offset .zero,
439
+ );
440
+ expect (find.text ('Page 2' ), findsNothing);
441
+ });
442
+
443
+ testWidgets ('Back swipe more than halfway is interrupted by route pop' , (WidgetTester tester) async {
444
+ // Regression test for https://github.com/flutter/flutter/issues/141268
445
+ final GlobalKey scaffoldKey = GlobalKey ();
446
+
447
+ await tester.pumpWidget (
448
+ CupertinoApp (
449
+ home: CupertinoPageScaffold (
450
+ key: scaffoldKey,
451
+ child: Center (
452
+ child: Column (
453
+ children: < Widget > [
454
+ const Text ('Page 1' ),
455
+ CupertinoButton (
456
+ onPressed: () {
457
+ Navigator .push <void >(scaffoldKey.currentContext! , CupertinoPageRoute <void >(
458
+ builder: (BuildContext context) {
459
+ return const CupertinoPageScaffold (
460
+ child: Center (child: Text ('Page 2' )),
461
+ );
462
+ },
463
+ ));
464
+ },
465
+ child: const Text ('Push Page 2' ),
466
+ ),
467
+ ],
468
+ ),
469
+ ),
470
+ ),
471
+ ),
472
+ );
473
+
474
+ expect (find.text ('Page 1' ), findsOneWidget);
475
+ expect (find.text ('Page 2' ), findsNothing);
476
+
477
+ await tester.tap (find.text ('Push Page 2' ));
478
+ await tester.pumpAndSettle ();
479
+ expect (find.text ('Page 1' ), findsNothing);
480
+ expect (find.text ('Page 2' ), findsOneWidget);
481
+
482
+ // Start a back gesture and move it more than 50% across the screen.
483
+ final TestGesture gesture = await tester.startGesture (const Offset (5.0 , 300.0 ));
484
+ await gesture.moveBy (const Offset (500.0 , 0.0 ));
485
+ await tester.pump ();
486
+ expect ( // The second route has been dragged to the right.
487
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 2' ), matching: find.byType (CupertinoPageScaffold ))),
488
+ const Offset (500.0 , 0.0 ),
489
+ );
490
+ expect ( // The first route is sliding in from the left.
491
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 1' ), matching: find.byType (CupertinoPageScaffold ))).dx,
492
+ lessThan (0 ),
493
+ );
494
+
495
+ // Programmatically pop and observe that Page 2 was popped as if there were
496
+ // no back gesture.
497
+ Navigator .pop <void >(scaffoldKey.currentContext! );
498
+ await tester.pumpAndSettle ();
499
+ expect (
500
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 1' ), matching: find.byType (CupertinoPageScaffold ))),
501
+ Offset .zero,
502
+ );
503
+ expect (find.text ('Page 2' ), findsNothing);
504
+ });
505
+
506
+ testWidgets ('Back swipe less than halfway is interrupted by route push' , (WidgetTester tester) async {
507
+ // Regression test for https://github.com/flutter/flutter/issues/141268
508
+ final GlobalKey scaffoldKey = GlobalKey ();
509
+
510
+ await tester.pumpWidget (
511
+ CupertinoApp (
512
+ home: CupertinoPageScaffold (
513
+ key: scaffoldKey,
514
+ child: Center (
515
+ child: Column (
516
+ children: < Widget > [
517
+ const Text ('Page 1' ),
518
+ CupertinoButton (
519
+ onPressed: () {
520
+ Navigator .push <void >(scaffoldKey.currentContext! , CupertinoPageRoute <void >(
521
+ builder: (BuildContext context) {
522
+ return const CupertinoPageScaffold (
523
+ child: Center (child: Text ('Page 2' )),
524
+ );
525
+ },
526
+ ));
527
+ },
528
+ child: const Text ('Push Page 2' ),
529
+ ),
530
+ ],
531
+ ),
532
+ ),
533
+ ),
534
+ ),
535
+ );
536
+
537
+ expect (find.text ('Page 1' ), findsOneWidget);
538
+ expect (find.text ('Page 2' ), findsNothing);
539
+
540
+ await tester.tap (find.text ('Push Page 2' ));
541
+ await tester.pumpAndSettle ();
542
+ expect (find.text ('Page 1' ), findsNothing);
543
+ expect (find.text ('Page 2' ), findsOneWidget);
544
+
545
+ // Start a back gesture and move it less than 50% across the screen.
546
+ final TestGesture gesture = await tester.startGesture (const Offset (5.0 , 300.0 ));
547
+ await gesture.moveBy (const Offset (100.0 , 0.0 ));
548
+ await tester.pump ();
549
+ expect ( // The second route has been dragged to the right.
550
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 2' ), matching: find.byType (CupertinoPageScaffold ))),
551
+ const Offset (100.0 , 0.0 ),
552
+ );
553
+ expect ( // The first route is sliding in from the left.
554
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 1' ), matching: find.byType (CupertinoPageScaffold ))).dx,
555
+ lessThan (0 ),
556
+ );
557
+
558
+ // Programmatically push and observe that Page 3 was pushed as if there were
559
+ // no back gesture.
560
+ Navigator .push <void >(scaffoldKey.currentContext! , CupertinoPageRoute <void >(
561
+ builder: (BuildContext context) {
562
+ return const CupertinoPageScaffold (
563
+ child: Center (child: Text ('Page 3' )),
564
+ );
565
+ },
566
+ ));
567
+ await tester.pumpAndSettle ();
568
+ expect (find.text ('Page 1' ), findsNothing);
569
+ expect (find.text ('Page 2' ), findsNothing);
570
+ expect (
571
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 3' ), matching: find.byType (CupertinoPageScaffold ))),
572
+ Offset .zero,
573
+ );
574
+ });
575
+
576
+ testWidgets ('Back swipe more than halfway is interrupted by route push' , (WidgetTester tester) async {
577
+ // Regression test for https://github.com/flutter/flutter/issues/141268
578
+ final GlobalKey scaffoldKey = GlobalKey ();
579
+
580
+ await tester.pumpWidget (
581
+ CupertinoApp (
582
+ home: CupertinoPageScaffold (
583
+ key: scaffoldKey,
584
+ child: Center (
585
+ child: Column (
586
+ children: < Widget > [
587
+ const Text ('Page 1' ),
588
+ CupertinoButton (
589
+ onPressed: () {
590
+ Navigator .push <void >(scaffoldKey.currentContext! , CupertinoPageRoute <void >(
591
+ builder: (BuildContext context) {
592
+ return const CupertinoPageScaffold (
593
+ child: Center (child: Text ('Page 2' )),
594
+ );
595
+ },
596
+ ));
597
+ },
598
+ child: const Text ('Push Page 2' ),
599
+ ),
600
+ ],
601
+ ),
602
+ ),
603
+ ),
604
+ ),
605
+ );
606
+
607
+ expect (find.text ('Page 1' ), findsOneWidget);
608
+ expect (find.text ('Page 2' ), findsNothing);
609
+
610
+ await tester.tap (find.text ('Push Page 2' ));
611
+ await tester.pumpAndSettle ();
612
+ expect (find.text ('Page 1' ), findsNothing);
613
+ expect (find.text ('Page 2' ), findsOneWidget);
614
+
615
+ // Start a back gesture and move it more than 50% across the screen.
616
+ final TestGesture gesture = await tester.startGesture (const Offset (5.0 , 300.0 ));
617
+ await gesture.moveBy (const Offset (500.0 , 0.0 ));
618
+ await tester.pump ();
619
+ expect ( // The second route has been dragged to the right.
620
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 2' ), matching: find.byType (CupertinoPageScaffold ))),
621
+ const Offset (500.0 , 0.0 ),
622
+ );
623
+ expect ( // The first route is sliding in from the left.
624
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 1' ), matching: find.byType (CupertinoPageScaffold ))).dx,
625
+ lessThan (0 ),
626
+ );
627
+
628
+ // Programmatically push and observe that Page 3 was pushed as if there were
629
+ // no back gesture.
630
+ Navigator .push <void >(scaffoldKey.currentContext! , CupertinoPageRoute <void >(
631
+ builder: (BuildContext context) {
632
+ return const CupertinoPageScaffold (
633
+ child: Center (child: Text ('Page 3' )),
634
+ );
635
+ },
636
+ ));
637
+ await tester.pumpAndSettle ();
638
+ expect (find.text ('Page 1' ), findsNothing);
639
+ expect (find.text ('Page 2' ), findsNothing);
640
+ expect (
641
+ tester.getTopLeft (find.ancestor (of: find.text ('Page 3' ), matching: find.byType (CupertinoPageScaffold ))),
642
+ Offset .zero,
643
+ );
644
+ });
645
+
380
646
testWidgets ('Fullscreen route animates correct transform values over time' , (WidgetTester tester) async {
381
647
await tester.pumpWidget (
382
648
CupertinoApp (
0 commit comments