Navigation
Stack screens, pass data, get a result back
Navigation and routes
A single-screen app doesn't exist. As soon as there's a list, there's a detail view; as soon as there's a detail view, there's a back button, a swipe gesture on iOS, a hardware key on Android, and the question of what stays in memory in the meantime.
Flutter models this as a stack. The visible screen is the one on top; pushing adds one above it, popping removes it and reveals the previous one. The Navigator, provided for free by MaterialApp, holds this stack, animates transitions according to platform conventions, and hooks into the hardware back button. The model is simple, and that is precisely why you need to understand its limits before choosing a more elaborate tool.
This is also the topic where the costliest bad habits take hold: named routes with untyped arguments that the compiler doesn't check, a stack that grows indefinitely because a login screen is pushed instead of replaced, a context used after an await when the screen has already disappeared. We'll cover all three.
Pushing and popping
The most direct form builds the destination screen in place:
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion