Tutorials
Move sign-in, tabs and logout without losing the guest path
Sign-in cancellation, retained tabs and private-only logout without losing the waiting guest screen.
Start with the go_router picker or the auto_route picker. This chapter extends that same application; it does not introduce a fourth router or a global navigation helper. The complete code lives in the unpublished migration fixture, not the 2.4.0 archive.
The go_router source has a persistent guest branch outside Account's private tabs. This matters: restoring the same Product URL is not sufficient if its original Catalog caller has already been disposed. The common acceptance test requires the same guest Catalog State and a working pending selection, not just the same visible page. No router gets a weaker expectation.
1. Run the account journey
From the Ark Navigation checkout:
cd tool/migration/source_routers
flutter pub get
flutter test test/account_migration_test.dart
There are seven Widget scenarios for each of the three routers: 21 in total. The tests cover button/platform cancellation, Back after sign-in, retained Product identity and private-only logout, one-time private results, and unmount during sign-in or a private selection, and Back followed by re-entry. The CI job also regenerates the source routers and checks that the committed generated files do not drift.
To inspect the UI, use the entrypoint described in the
fixture README.
Choose MIGRATION_SOURCE=go-router, auto-route, or ark.
The sign-in button changes only local demo state; there is no real identity
provider, password, network call, token storage or access revocation service.
The intended acceptance journey is:
- Home → Browse catalog → Open product. Leave this guest Product open.
- Open account. You see Sign in, not the private Catalog.
- Cancel sign in. You return to exactly the same guest Product.
- Open account again → Continue sign in. Account shows its own Catalog.
- Open product in Account → Profile tab → Catalog tab. The same private Product entry is still open; switching tabs did not push another Product.
- Logout. The guest Product from step 1 reappears. Selecting it still returns the ID to its original guest caller exactly once.
- Open account again. Sign-in is required again; after signing in, its Catalog starts without the previous private Product.
Cancelling login is not cancelling the guest Product. Logout is not replacing the whole root stack with Home. Those two mistakes would lose the user's work.
2. Locate the files you actually need to replace
| Responsibility | go_router source | auto_route source | Ark target |
|---|---|---|---|
| Declare private navigation | GoAccountShell | AutoAppRouter | PickerGraph |
| Enter sign-in | GoSourceApp redirect | AutoAccessGuard | AccountRedirect |
| Finish or cancel sign-in | GoSignInRoute | AutoSignInScreen | SignInDestination page in PickerGraph |
| Select a retained tab and logout | GoAccountShell | AutoAccountScreen | ArkAccountScreen |
The shared AccountPage contains buttons and a child slot. It does not store navigation entries. The router-specific shell supplies the selected branch and callbacks.
MigrationApp owns the AccessState instance and closes it with the app. Each router owns and disposes its own root controller. AccessState does not contain any router; shared pages do not import a source routing package.
3. Transfer sign-in behavior, not the resolver callback
In go_router, GoSourceApp
owns the composition. Its _openAccount pushes the typed GoSignInRoute as a
root overlay when signed out; when already signed in, it selects the typed
private route with go. The root redirect additionally protects private route
requests. These are different responsibilities: choosing how to preserve the
current guest flow, and refusing an unauthorized private target.
On successful sign-in, GoSignInRoute removes the login overlay with pop,
then selects the allowlisted private target with its generated go method.
The persistent outer shell keeps the guest Navigator alive. Cancel only pops
Sign in; it never selects the private branch.
GoAppScope exposes this source app owner's callbacks through context. It is not an Ark adapter, another router, or a global service locator. Product input and result still use real generated go_router route classes.
In auto_route, AutoAccessGuard suspends the requested AutoAccountRoute using
resolver.redirectUntil. AutoSignInScreen reports success or cancellation.
The guard resolves once; auto_route removes the temporary login route.
Platform Back also cancels the pending guarded request. Do not copy this
resolver object into Ark: it belongs to auto_route's navigation lifecycle.
In Ark, requesting AccountDestination passes through AccountRedirect.
When signed out, the redirect changes that target to SignInDestination.
Successful sign-in uses replaceTop with AccountDestination; cancel pops only
the root login entry. Private child mounts additionally have a
PrivateAccessGuard that denies
direct child entry while signed out. A denial does not itself open Sign in.
Go and Ark use the closed
ReturnTarget enum for accepted account
targets. AutoRoute retains the original typed guarded request instead.
There is no arbitrary external returnTo URL in any of these flows.
This is not a promise that all policy callbacks execute in the same order. go_router's onEnter and redirect, auto_route's resolver and Ark's Redirect/Guard have different contracts. The tests compare this journey's outcome, not interchangeable policy implementations.
4. Preserve the private stack when changing tabs
GoSourceApp's outer StatefulShellRoute has Guest and Account branches.
Inside Account, GoAccountShell declares the private Catalog and Profile
branches. Their goBranch switches cannot dispose the sibling guest Navigator.
An existing private branch is selected without initialLocation: true. AutoAccountScreen
uses AutoTabsRouter and setActiveIndex; the Catalog tab hosts a nested
AutoRouter for Catalog → Product.
PickerGraph defines two private child Scopes under the root: Catalog and
Profile. ArkAccountScreen initializes their entries, then calls
activateBranch to select Catalog. The shared Catalog Module is mounted
twice: guest in the root stack, private in the Catalog Scope.
User tab changes explicitly request NavigationHistoryMode.push in this
fixture so browser Back can revisit the selected tab. Internal initialization
uses replacement history; it is not an additional user visit.
ArkCatalogScreen receives the current Mount ID from its Entry. Its product
call uses placed(mountId: widget.mountId), so it cannot accidentally open
the guest Product from a private Catalog, or vice versa. Product's Select/Cancel
explicitly pop its owning Scope. No global or static Navigator key selects a tab.
Switching a tab and resetting a branch are deliberately different operations. The tests save each router's own Product identity before switching and compare it after switching back. They do not compare opaque identities between routers, or promise Flutter State retention for an arbitrary host. This fixture keeps both Ark NavigationOutlets in an IndexedStack: the private Catalog caller remains mounted when Profile is selected. A separate selection-after-switch check verifies delivery back to that caller, not just the visible Product. Using only NavigationActiveOutlet would not, by itself, promise the same Widget State lifetime for an inactive branch.
5. Close the private flow without closing the guest caller
GoAccountShell asks its owner to leave Account. GoSourceApp first selects the retained Guest branch, waits for that frame to finish, then updates its RoutingConfig with a fresh private branch and private shell. The Guest branch, its route definitions and outer shell key are reused. Thus private entries are disposed, while the original guest Catalog and its pending Future survive. Back from the private Product still pops that Product; Back at Account's base uses PopScope to leave Account and clear its branches without signing out. The frame wait is an explicit ordering boundary, not an atomic navigation transaction or a timeout-based workaround. Keys and configuration belong to the app State; there are no global keys or handwritten RouteMatchList rewrites.
AutoAccountScreen removes the owning AutoAccountRoute from the root StackRouter; its nested routers go with it.
ArkAccountScreen first resets the Catalog and Profile branches and then removes its exact shell Entry. These are explicit ordered operations, not an atomic cross-Scope transaction. The root guest entries are never replaced. The shell also intercepts root Back with PopScope so leaving Account closes its branches, rather than leaving invisible private Entries behind.
Access is marked signed out before logout removes source routes. A removed
private picker must not report an ordinary nullable selection while its widgets
are being disposed. The source private Catalog screens check both mounted
and access after awaiting. Ark distinguishes NavigationRemoved from
NavigationPopped; removal is not a successful or cancelled selection.
Do not apply the sign-out check to the guest caller: it legitimately remains alive while the user signs out of Account.
6. Know what is still outside this chapter
Executable account tests use real router widgets and platform Back messages. They do not prove browser Back/Forward/reload, native gesture delivery, external authentication or app-wide session expiry handling. Cold private URLs, canonical/alias handling, invalid startup input and the separate browser job are described in the direct-link walkthrough.
The cold-link host now supplies explicit URI parent plans, and account initialization preserves already restored branches. These have their own tests; a passing interactive tab test alone is still not proof of cold links or browser history.