Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter 2.0 pushAndRemoveUntil not working

Not sure how to clear the stack and route to a new page after implementing the Flutter 2.0 routing.

The following isn't working:

Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context) => SignInPage()), (route) => false);

[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3075 pos 7: '!hasPage || isWaitingForExitingDecision': A page-based route cannot be completed using imperative api, provide a new list without the corresponding Page to Navigator.pages instead.

like image 637
mtical Avatar asked Oct 26 '22 12:10

mtical


People also ask

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.

How do you use Pushreplacement flutter?

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 Navigator pushReplacementNamed in flutter?

To use pushReplacementNamed, a Navigator. onGenerateRoute callback must be provided. Returns a Future that completes to the result value passed to pop when the pushed route is popped off the navigator. The provided arguments are passed to the pushed route via RouteSettings.


1 Answers

You can access your MaterialApp navigator with rootNavigator: true. See https://api.flutter.dev/flutter/widgets/Navigator/of.html. Try the following it is working.

Navigator.of(context, rootNavigator: 
true).pushAndRemoveUntil(MaterialPageRoute(builder: (context) => 
SignInPage()), (route) => false);
like image 62
Kyaw San Oo Avatar answered Oct 31 '22 13:10

Kyaw San Oo