📱 Flutter
Advanced
What is Navigator.pushAndRemoveUntil() in Flutter?
Answer
Navigator.pushAndRemoveUntil() navigates to a new route and removes all existing routes from the stack that satisfy a given predicate. To clear the entire stack: Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (_) => HomeScreen()), (route) => false). This is used after logout (to clear the authenticated stack before showing login), after completing an onboarding flow, or after a payment confirmation where you do not want the user to navigate back to intermediate screens.