Recipes

Stack rewrites and typed results

Choose exact operations for Login replacement, flow cleanup, parameter updates, and typed values returned from a popped page.

v1.1.0Intermediate

Stack rewrites and typed results

Replace Login with Home

Starting stack: [Welcome, Login]. Desired stack: [Welcome, Home].

dart
await navigation.replaceTop<void>(const HomeDestination());

Do not push Home: that would leave Login under it.

Clear onboarding completely

Starting stack: [Welcome, Permissions, ProfileSetup]. Desired stack: [Home].

dart
await navigation.replaceAll(<NavigationTarget<Object?>>[
  const NavigationTarget<Object?>(destination: HomeDestination()),
]);

Keep Cart but remove checkout steps

Starting stack: [Home, Cart, Address, Payment]. Desired stack after opening Receipt: [Home, Cart, Receipt].

dart
navigation.pushAndRemoveUntil<void>(
  const ReceiptDestination(),
  retain: const NavigationRouteIdMatcher(NavigationRouteId('cart')),
);

Update the current Product without ending its ticket

dart
await navigation.reconfigureTop<void>(
  const ProductDestination(productId: 'keyboard-43'),
);

Use replaceTop when the old Entry should end. Use reconfigureTop when it remains the same runtime Entry.

Return a typed value

Caller:

dart
final ticket = navigation.push<Address?>(const AddressPickerDestination());
final completion = await ticket.completed;
if (completion case NavigationPopped<Address?>(:final result)) {
  checkout.setAddress(result);
}

Picker:

dart
await context.readNavigation.pop(result: selectedAddress);

NavigationRemoved means a stack rewrite ended the Entry; it is deliberately different from a normal pop with null.