I need to replace my current screen and found replace
method in Navigator's API. But I didn't find any example for it. Maybe somebody knows hot to use it. Thanks.
Replace the current route of the navigator by pushing the given route and then disposing the previous route once the new route has finished animating in. If non-null, result will be used as the result of the route that is removed; the future that had been returned from pushing that old route will complete with result .
Push the given route onto the navigator, and then remove all the previous routes until the predicate returns true. The predicate may be applied to the same route more than once if Route. willHandlePopInternally is true. To remove routes until a route with a certain name, use the RoutePredicate returned from ModalRoute.
I usually use
Route route = MaterialPageRoute(builder: (context) => NextPage()); Navigator.pushReplacement(context, route);
Hope it helps
I have never used Navigator.replace()
but this Navigator.pushReplacementNamed
might help you.
Navigator.pushReplacementNamed(context, '/thread_list');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With