Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Navigator.replace() example

Tags:

flutter

dart

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.

like image 749
Ruslan Leshchenko Avatar asked Jun 29 '18 12:06

Ruslan Leshchenko


People also ask

How do you use push replacement?

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 .

How do you use Pushandremoveuntil in Flutter?

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.


2 Answers

I usually use

Route route = MaterialPageRoute(builder: (context) => NextPage()); Navigator.pushReplacement(context, route); 

Hope it helps

like image 97
songoku1610 Avatar answered Sep 20 '22 18:09

songoku1610


I have never used Navigator.replace() but this Navigator.pushReplacementNamed might help you.

Navigator.pushReplacementNamed(context, '/thread_list'); 
like image 21
goops17 Avatar answered Sep 22 '22 18:09

goops17