@@ -540,4 +540,80 @@ void main() {
540
540
expect (find.text ('Page 1' ), isOnstage);
541
541
expect (find.text ('Page 2' ), findsNothing);
542
542
});
543
+
544
+ testWidgets ('Back swipe dismiss interrupted by route push' , (WidgetTester tester) async {
545
+ // Regression test for https://github.com/flutter/flutter/issues/28728
546
+ final GlobalKey scaffoldKey = GlobalKey ();
547
+
548
+ await tester.pumpWidget (
549
+ MaterialApp (
550
+ theme: ThemeData (platform: TargetPlatform .iOS),
551
+ home: Scaffold (
552
+ key: scaffoldKey,
553
+ body: Center (
554
+ child: RaisedButton (
555
+ onPressed: () {
556
+ Navigator .push <void >(scaffoldKey.currentContext, MaterialPageRoute <void >(
557
+ builder: (BuildContext context) {
558
+ return const Scaffold (
559
+ body: Center (child: Text ('route' )),
560
+ );
561
+ },
562
+ ));
563
+ },
564
+ child: const Text ('push' ),
565
+ ),
566
+ ),
567
+ ),
568
+ ),
569
+ );
570
+
571
+ // Check the basic iOS back-swipe dismiss transition. Dragging the pushed
572
+ // route halfway across the screen will trigger the iOS dismiss animation
573
+
574
+ await tester.tap (find.text ('push' ));
575
+ await tester.pumpAndSettle ();
576
+ expect (find.text ('route' ), findsOneWidget);
577
+ expect (find.text ('push' ), findsNothing);
578
+
579
+ TestGesture gesture = await tester.startGesture (const Offset (5 , 300 ));
580
+ await gesture.moveBy (const Offset (400 , 0 ));
581
+ await gesture.up ();
582
+ await tester.pump ();
583
+ expect ( // The 'route' route has been dragged to the right, halfway across the screen
584
+ tester.getTopLeft (find.ancestor (of: find.text ('route' ), matching: find.byType (Scaffold ))),
585
+ const Offset (400 , 0 ),
586
+ );
587
+ expect ( // The 'push' route is sliding in from the left.
588
+ tester.getTopLeft (find.ancestor (of: find.text ('push' ), matching: find.byType (Scaffold ))).dx,
589
+ lessThan (0 ),
590
+ );
591
+ await tester.pumpAndSettle ();
592
+ expect (find.text ('push' ), findsOneWidget);
593
+ expect (
594
+ tester.getTopLeft (find.ancestor (of: find.text ('push' ), matching: find.byType (Scaffold ))),
595
+ Offset .zero,
596
+ );
597
+ expect (find.text ('route' ), findsNothing);
598
+
599
+
600
+ // Run the dismiss animation 75%, which exposes the route "push" button,
601
+ // and then press the button. MaterialPageTransition duration is 300ms,
602
+ // 275 = 300 * 0.75.
603
+
604
+ await tester.tap (find.text ('push' ));
605
+ await tester.pumpAndSettle ();
606
+ expect (find.text ('route' ), findsOneWidget);
607
+ expect (find.text ('push' ), findsNothing);
608
+
609
+ gesture = await tester.startGesture (const Offset (5 , 300 ));
610
+ await gesture.moveBy (const Offset (400 , 0 )); // drag halfway
611
+ await gesture.up ();
612
+ await tester.pump (const Duration (milliseconds: 275 )); // partially dismiss "route"
613
+ expect (find.text ('route' ), findsOneWidget);
614
+ await tester.tap (find.text ('push' ));
615
+ await tester.pumpAndSettle ();
616
+ expect (find.text ('route' ), findsOneWidget);
617
+ expect (find.text ('push' ), findsNothing);
618
+ });
543
619
}
0 commit comments