ワンクリックで
flutter-routing-and-navigation
Move between or deep link to different screens or routes within a Flutter application
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Move between or deep link to different screens or routes within a Flutter application
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Configure your Flutter app to support assistive technologies like Screen Readers
Add animated effects to your Flutter app
Measure and reduce the size of the Flutter app bundle, APK, or IPA
Use the Flutter team's recommended app architecture
Execute long-running tasks in a background thread in Flutter
Set up a macOS environment for Flutter development
| name | flutter-routing-and-navigation |
| description | Move between or deep link to different screens or routes within a Flutter application |
| metadata | {"model":"models/gemini-3.1-pro-preview","last_modified":"Mon, 02 Mar 2026 21:33:05 GMT"} |
Implements robust navigation and routing in Flutter applications. Evaluates application requirements to select the appropriate routing strategy (imperative Navigator, declarative Router, or nested navigation), handles deep linking, and manages data passing between routes while adhering to Flutter best practices.
Evaluate the application's navigation requirements using the following decision tree:
Router API (typically via a routing package like go_router).Navigator.Navigator API (Navigator.push and Navigator.pop) with MaterialPageRoute or CupertinoPageRoute.MaterialApp.routes or onGenerateRoute, but note the limitations regarding deep link customization and web forward-button support.STOP AND ASK THE USER: "Based on your app's requirements, should we implement simple imperative navigation (Navigator.push), declarative routing (Router/go_router for deep links/web), or a nested navigation flow?"
If simple navigation is selected, use the Navigator widget to push and pop Route objects.
Pushing a new route:
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => const SecondScreen(),
),
);
Popping a route:
Navigator.of(context).pop();
Pass data to new screens using constructor arguments (preferred for imperative navigation) or RouteSettings (for named routes).
Passing via Constructor:
// Navigating and passing data
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (context) => DetailScreen(todo: currentTodo),
),
);
// Receiving data
class DetailScreen extends StatelessWidget {
const DetailScreen({super.key, required this.todo});
final Todo todo;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(todo.title)),
body: Text(todo.description),
);
}
}
Passing via RouteSettings (Named Routes):
// Navigating and passing data
Navigator.pushNamed(
context,
'/details',
arguments: currentTodo,
);
// Extracting data in the destination widget
final todo = ModalRoute.of(context)!.settings.arguments as Todo;
If named routes are explicitly required, configure MaterialApp with initialRoute and routes or onGenerateRoute.
MaterialApp(
title: 'Named Routes App',
initialRoute: '/',
routes: {
'/': (context) => const FirstScreen(),
'/second': (context) => const SecondScreen(),
},
// OR use onGenerateRoute for dynamic argument extraction
onGenerateRoute: (settings) {
if (settings.name == '/details') {
final args = settings.arguments as Todo;
return MaterialPageRoute(
builder: (context) => DetailScreen(todo: args),
);
}
assert(false, 'Need to implement ${settings.name}');
return null;
},
)
For sub-flows, instantiate a new Navigator widget within the widget tree. You MUST assign a GlobalKey<NavigatorState> to manage the nested stack.
class SetupFlowState extends State<SetupFlow> {
final _navigatorKey = GlobalKey<NavigatorState>();
void _onDiscoveryComplete() {
_navigatorKey.currentState!.pushNamed('/select_device');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Setup Flow')),
body: Navigator(
key: _navigatorKey,
initialRoute: '/find_devices',
onGenerateRoute: _onGenerateRoute,
),
);
}
Route<Widget> _onGenerateRoute(RouteSettings settings) {
Widget page;
switch (settings.name) {
case '/find_devices':
page = WaitingPage(onWaitComplete: _onDiscoveryComplete);
break;
case '/select_device':
page = const SelectDevicePage();
break;
default:
throw StateError('Unexpected route name: ${settings.name}!');
}
return MaterialPageRoute(builder: (context) => page, settings: settings);
}
}
Review the implemented routing logic to ensure stability:
Navigator.pop() does not inadvertently close the application if the stack is empty (use Navigator.canPop(context) if necessary).initialRoute, verify that the home property is NOT defined in MaterialApp.ModalRoute, verify that null checks or type casts are safely handled.MaterialApp.routes) for applications requiring complex deep linking or web support; use the Router API instead.home property in MaterialApp if an initialRoute is provided.GlobalKey<NavigatorState> when implementing a nested Navigator to ensure the correct navigation stack is targeted.ModalRoute.of(context)!.settings.arguments to the specific expected type and handle potential nulls if the route can be accessed without arguments.