pushAndRemoveUntil static method
Future
pushAndRemoveUntil({
- required BuildContext context,
- required Widget screen,
- bool isCupertinoPush = true,
Pushes a new route and removes all previous routes from the stack.
This is useful for scenarios like navigating to a home screen after a login or splash screen, ensuring the user cannot navigate back.
context: The build context from which to navigate.
screen: The widget to display as the new screen.
isCupertinoPush: If true, uses a CupertinoPageRoute. Otherwise, uses a MaterialPageRoute.
Implementation
static Future pushAndRemoveUntil({
required BuildContext context,
required Widget screen,
bool isCupertinoPush = true,
}) async {
if (isCupertinoPush) {
return Navigator.pushAndRemoveUntil(
context,
CupertinoPageRoute(builder: (context) => screen),
(route) => false,
);
} else {
return Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => screen),
(route) => false,
);
}
}