flutter-routing-and-navigation▌
flutter/skills · updated Apr 8, 2026
Navigate between screens, handle deep linking, and manage data passing in Flutter applications.
- ›Evaluates app requirements to select the optimal routing strategy: imperative Navigator for simple flows, declarative Router / go_router for deep linking and web support, or nested Navigator for independent sub-flows
- ›Supports data passing between routes via constructor arguments (preferred) or RouteSettings with type-safe argument extraction
- ›Implements named routes with MaterialApp.routes
flutter-navigation-routing
Goal
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.
Instructions
1. Determine Routing Strategy (Decision Logic)
Evaluate the application's navigation requirements using the following decision tree:
- Condition A: Does the app require complex deep linking, web URL synchronization, or advanced routing logic?
- Action: Use the declarative
RouterAPI (typically via a routing package likego_router).
- Action: Use the declarative
- Condition B: Does the app require independent sub-flows (e.g., a multi-step setup wizard or persistent bottom navigation bars)?
- Action: Implement a Nested
Navigator.
- Action: Implement a Nested
- Condition C: Is it a simple application with basic screen-to-screen transitions and no complex deep linking?
- Action: Use the imperative
NavigatorAPI (Navigator.pushandNavigator.pop) withMaterialPageRouteorCupertinoPageRoute.
- Action: Use the imperative
- Condition D: Are Named Routes requested?
- Action: Use
MaterialApp.routesoronGenerateRoute, but note the limitations regarding deep link customization and web forward-button support.
- Action: Use
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?"
2. Implement Basic Imperative Navigation
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();
3. Implement Data Passing Between Screens
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;
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;
4. Implement Named Routes (If Required)
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;
},
)
5. Implement Nested Navigation
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');
}
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);
}
}
6. Validate and Fix
Review the implemented routing logic to ensure stability:
- Verify that
Navigator.pop()does not inadvertently close the application if the stack is empty (useNavigator.canPop(context)if necessary). - If using
initialRoute, verify that thehomeproperty is NOT defined inMaterialApp. - If extracting arguments via
ModalRoute, verify that null checks or type casts are safely handled.
Constraints
- Do NOT use named routes (
MaterialApp.routes) for applications requiring complex deep linking or web support; use theRouterAPI instead. - Do NOT define a
homeproperty inMaterialAppif aninitialRouteis provided. - You MUST use a
GlobalKey<NavigatorState>when implementing a nestedNavigatorto ensure the correct navigation stack is targeted. - Do NOT include external URLs or links in the generated code or comments.
- Always cast
ModalRoute.of(context)!.settings.argumentsto the specific expected type and handle potential nulls if the route can be accessed without arguments.
Ratings
4.5★★★★★10 reviews- ★★★★★Shikha Mishra· Oct 10, 2024
flutter-routing-and-navigation is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- ★★★★★Piyush G· Sep 9, 2024
Keeps context tight: flutter-routing-and-navigation is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Chaitanya Patil· Aug 8, 2024
Registry listing for flutter-routing-and-navigation matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Sakshi Patil· Jul 7, 2024
flutter-routing-and-navigation reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Ganesh Mohane· Jun 6, 2024
I recommend flutter-routing-and-navigation for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Oshnikdeep· May 5, 2024
Useful defaults in flutter-routing-and-navigation — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Dhruvi Jain· Apr 4, 2024
flutter-routing-and-navigation has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Rahul Santra· Mar 3, 2024
Solid pick for teams standardizing on skills: flutter-routing-and-navigation is focused, and the summary matches what you get after install.
- ★★★★★Pratham Ware· Feb 2, 2024
We added flutter-routing-and-navigation from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Yash Thakker· Jan 1, 2024
flutter-routing-and-navigation fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.