@@ -1795,6 +1795,82 @@ void main() {
1795
1795
expect (find.text (secondHeader), findsOneWidget);
1796
1796
});
1797
1797
1798
+ testWidgets ('Should have only one SnackBar during back swipe navigation' , (WidgetTester tester) async {
1799
+ const String snackBarText = 'hello snackbar' ;
1800
+ const Key snackTarget = Key ('snack-target' );
1801
+ const Key transitionTarget = Key ('transition-target' );
1802
+
1803
+ Widget buildApp () {
1804
+ final PageTransitionsTheme pageTransitionTheme = PageTransitionsTheme (
1805
+ builders: < TargetPlatform , PageTransitionsBuilder > {
1806
+ for (final TargetPlatform platform in TargetPlatform .values)
1807
+ platform: const CupertinoPageTransitionsBuilder (),
1808
+ },
1809
+ );
1810
+ return MaterialApp (
1811
+ theme: ThemeData (pageTransitionsTheme: pageTransitionTheme),
1812
+ initialRoute: '/' ,
1813
+ routes: < String , WidgetBuilder > {
1814
+ '/' : (BuildContext context) {
1815
+ return Scaffold (
1816
+ body: Center (
1817
+ child: ElevatedButton (
1818
+ key: transitionTarget,
1819
+ child: const Text ('PUSH' ),
1820
+ onPressed: () {
1821
+ Navigator .of (context).pushNamed ('/second' );
1822
+ },
1823
+ ),
1824
+ ),
1825
+
1826
+ );
1827
+ },
1828
+ '/second' : (BuildContext context) {
1829
+ return Scaffold (
1830
+ floatingActionButton: FloatingActionButton (
1831
+ key: snackTarget,
1832
+ onPressed: () async {
1833
+ ScaffoldMessenger .of (context).showSnackBar (
1834
+ const SnackBar (
1835
+ content: Text (snackBarText),
1836
+ ),
1837
+ );
1838
+ },
1839
+ child: const Text ('X' ),
1840
+ ),
1841
+ );
1842
+ },
1843
+ },
1844
+ );
1845
+ }
1846
+ await tester.pumpWidget (buildApp ());
1847
+
1848
+ // Transition to second page.
1849
+ await tester.tap (find.byKey (transitionTarget));
1850
+ await tester.pumpAndSettle ();
1851
+
1852
+ // Present SnackBar
1853
+ await tester.tap (find.byKey (snackTarget));
1854
+ await tester.pump (); // schedule animation
1855
+ expect (find.text (snackBarText), findsOneWidget);
1856
+ await tester.pump (); // begin animation
1857
+ expect (find.text (snackBarText), findsOneWidget);
1858
+ await tester.pump (const Duration (milliseconds: 750 ));
1859
+ expect (find.text (snackBarText), findsOneWidget);
1860
+
1861
+ // Start the gesture at the edge of the screen.
1862
+ final TestGesture gesture = await tester.startGesture (const Offset (5.0 , 200.0 ));
1863
+ // Trigger the swipe.
1864
+ await gesture.moveBy (const Offset (100.0 , 0.0 ));
1865
+
1866
+ // Back gestures should trigger and draw the hero transition in the very same
1867
+ // frame (since the "from" route has already moved to reveal the "to" route).
1868
+ await tester.pump ();
1869
+
1870
+ // We should have only one SnackBar displayed on the screen.
1871
+ expect (find.text (snackBarText), findsOneWidget);
1872
+ });
1873
+
1798
1874
testWidgets ('SnackBars should be shown above the bottomSheet' , (WidgetTester tester) async {
1799
1875
await tester.pumpWidget (const MaterialApp (
1800
1876
home: Scaffold (
0 commit comments