@@ -536,15 +536,20 @@ public static Future pushNamed(BuildContext context, string routeName, object ar
536536 return of ( context ) . pushNamed ( routeName , arguments : arguments ) ;
537537 }
538538
539+ public static Future < T > pushReplacementNamed < T , TO > ( BuildContext context , string routeName ,
540+ TO result = default , object arguments = null ) {
541+ return of ( context ) . pushReplacementNamed < T , TO > ( routeName , arguments : arguments , result : result ) ;
542+ }
543+
539544 public static Future pushReplacementNamed ( BuildContext context , string routeName ,
540545 object result = default , object arguments = null ) {
541546 return of ( context ) . pushReplacementNamed ( routeName , arguments : arguments , result : result ) ;
542547 }
543548
544- public static Future popAndPushNamed ( BuildContext context , string routeName ,
545- object result = default ,
549+ public static Future < T > popAndPushNamed < T , TO > ( BuildContext context , string routeName ,
550+ TO result = default ,
546551 object arguments = null ) {
547- return of ( context ) . popAndPushNamed ( routeName , result : result , arguments : arguments ) ;
552+ return of ( context ) . popAndPushNamed < T , TO > ( routeName , result : result , arguments : arguments ) ;
548553 }
549554
550555 public static Future < T > pushNamedAndRemoveUntil < T > ( BuildContext context , string newRouteName ,
@@ -556,8 +561,8 @@ public static Future<T> push<T>(BuildContext context, Route route) {
556561 return of ( context ) . push < T > ( route ) ;
557562 }
558563
559- public static Future pushReplacement ( BuildContext context , Route newRoute , object result = default ) {
560- return of ( context ) . pushReplacement ( newRoute , result ) ;
564+ public static Future < T > pushReplacement < T , TO > ( BuildContext context , Route < T > newRoute , TO result = default ) {
565+ return of ( context ) . pushReplacement < T , TO > ( newRoute , result ) ;
561566 }
562567
563568
@@ -1652,7 +1657,7 @@ public Route<T> _routeNamed<T>(string name, object arguments, bool allowNull = f
16521657 arguments : arguments
16531658 ) ;
16541659
1655- var routeee = ( Route ) widget . onGenerateRoute ( settings ) ;
1660+ var routeee = widget . onGenerateRoute ( settings ) ;
16561661 Route < T > route = routeee as Route < T > ;
16571662 if ( route == null && ! allowNull ) {
16581663 D . assert ( ( ) => {
@@ -1701,6 +1706,14 @@ public Future pushNamed(
17011706 return push ( _routeNamed ( routeName , arguments : arguments ) ) ;
17021707 }
17031708
1709+ public Future < T > pushReplacementNamed < T , TO > (
1710+ string routeName ,
1711+ TO result = default ,
1712+ object arguments = null
1713+ ) {
1714+ return pushReplacement < T , TO > ( _routeNamed < T > ( routeName , arguments : arguments ) , result : result ) ;
1715+ }
1716+
17041717 public Future pushReplacementNamed (
17051718 string routeName ,
17061719 object result = default ,
@@ -1709,13 +1722,14 @@ public Future pushReplacementNamed(
17091722 return pushReplacement ( _routeNamed ( routeName , arguments : arguments ) , result : result ) ;
17101723 }
17111724
1712- public Future popAndPushNamed (
1725+
1726+ public Future < T > popAndPushNamed < T , TO > (
17131727 string routeName ,
1714- object result = default ,
1728+ TO result = default ,
17151729 object arguments = null
17161730 ) {
1717- pop < object > ( result ) ;
1718- return pushNamed ( routeName , arguments : arguments ) ;
1731+ pop < TO > ( result ) ;
1732+ return pushNamed < T > ( routeName , arguments : arguments ) ;
17191733 }
17201734
17211735 public Future < T > pushNamedAndRemoveUntil < T > (
@@ -1797,6 +1811,41 @@ void _afterNavigation(Route route) {
17971811
17981812
17991813
1814+ public Future < T > pushReplacement < T , TO > ( Route < T > newRoute , TO result ) {
1815+ D . assert ( ! _debugLocked ) ;
1816+ D . assert ( ( ) => {
1817+ _debugLocked = true ;
1818+ return true ;
1819+ } ) ;
1820+ D . assert ( newRoute != null ) ;
1821+ D . assert ( newRoute . _navigator == null ) ;
1822+ D . assert ( _history . isNotEmpty ( ) ) ;
1823+
1824+ bool anyEntry = false ;
1825+ foreach ( var historyEntry in _history ) {
1826+ if ( _RouteEntry . isPresentPredicate ( historyEntry ) ) {
1827+ anyEntry = true ;
1828+ }
1829+ }
1830+ D . assert ( anyEntry , ( ) => "Navigator has no active routes to replace." ) ;
1831+ _RouteEntry lastEntry = null ;
1832+ foreach ( var historyEntry in _history ) {
1833+ if ( _RouteEntry . isPresentPredicate ( historyEntry ) ) {
1834+ lastEntry = historyEntry ;
1835+ }
1836+ }
1837+ lastEntry . complete ( result , isReplaced : true ) ;
1838+
1839+ _history . Add ( new _RouteEntry ( newRoute , initialState : _RouteLifecycle . pushReplace ) ) ;
1840+ _flushHistoryUpdates ( ) ;
1841+ D . assert ( ( ) => {
1842+ _debugLocked = false ;
1843+ return true ;
1844+ } ) ;
1845+ _afterNavigation ( newRoute ) ;
1846+ return newRoute . popped . to < T > ( ) ;
1847+ }
1848+
18001849 public Future pushReplacement ( Route newRoute , object result ) {
18011850 D . assert ( ! _debugLocked ) ;
18021851 D . assert ( ( ) => {
@@ -1832,6 +1881,7 @@ public Future pushReplacement(Route newRoute, object result) {
18321881 return newRoute . popped . to < object > ( ) ;
18331882 }
18341883
1884+
18351885 public Future < T > pushAndRemoveUntil < T > ( Route < T > newRoute , RoutePredicate predicate ) {
18361886 D . assert ( ! _debugLocked ) ;
18371887 D . assert ( ( ) => {
0 commit comments