Navigation 在 Flutter 中是在屏幕(pages/routes)之间移动 — 使用 Navigator(一个路由堆栈)进行基本导航,或对于更复杂的应用使用声明式路由包。理解导航对构建多屏幕应用至关重要。
使用 Navigator 进行基本导航(一个堆栈)
dart
// the Navigator manages a STACK of routes (screens)
// PUSH a new screen onto the stack (navigate to it)
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
// POP — go back (remove the top screen, return to the previous)
Navigator.pop(context);
text
Think of navigation as a STACK of screens:
→ PUSH adds a screen on top (navigate forward)
→ POP removes the top screen (go back)
→ the back button / gesture also pops
