ナビゲーションとはFlutterで画面(ページ/ルート)間を移動することです。基本的なナビゲーションにはNavigator(ルートのスタック)を使用し、より複雑なアプリには宣言的なルーティングパッケージを使用します。ナビゲーションを理解することは、マルチスクリーンアプリを構築するために不可欠です。
Navigatorを使った基本的なナビゲーション(スタック)
// 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);
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
