replaceStack static method
Future<void>
replaceStack(
- BuildContext context,
- List<
String> routes, { - NavTransitionType? transitionType,
- Duration? transitionDuration,
- Duration? reverseTransitionDuration,
Replace the entire navigation stack with an ordered list of routes.
The first route replaces everything; subsequent routes are pushed on top. Useful for deep-link handling or logout-then-login flows.
Implementation
static Future<void> replaceStack(
BuildContext context,
List<String> routes, {
NavTransitionType? transitionType,
Duration? transitionDuration,
Duration? reverseTransitionDuration,
}) async {
if (routes.isEmpty) return;
final NavTransitionType type = transitionType ?? _defaultTransition;
await pushNamedAndRemoveAll<void>(
context,
routes.first,
transitionType: type,
transitionDuration: transitionDuration,
reverseTransitionDuration: reverseTransitionDuration,
);
for (int i = 1; i < routes.length; i++) {
if (!context.mounted) return;
await pushNamed<void>(
context,
routes[i],
transitionType: type,
transitionDuration: transitionDuration,
reverseTransitionDuration: reverseTransitionDuration,
);
}
}