Flutter: Move to a new screen without back
You need to use Navigator.pushReplacement
when leaving the auth screen too. Not just when redirecting to login page.
You can use the pushAndRemoveUntil
method:
Push the given route onto the navigator that most tightly encloses the given context, and then remove all the previous routes until the
predicate
returns true. To remove all the routes below the pushed route, use a [RoutePredicate] that always returns false (e.g.(Route<dynamic> route) => false
).
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => MainPage()),
(Route<dynamic> route) => false,
);
You need to use
Navigator
.of(_context)
.pushReplacement(new MaterialPageRoute(builder: (BuildContext context) => page));
Where _context
is object of BuildContext
And page
is which page you directed to.