A VSCode extension that helps Flutter developers easily jump to the definition of classes generated by the AutoRoute package.
- Automatic Route Detection: Monitors Dart files for
*Routeclass names (e.g.,HomeRoute,SettingsRoute) - Inline CodeLens (smart): Displays "Jump to Definition" only when the corresponding widget file can be resolved from
routes.gr.dart - Indexed Discovery (no hardcoding): Uses VS Code’s workspace index to discover
routes.gr.dartanywhere in the workspace (no hardcoded paths) - Multi-file Support: Handles multiple
routes.gr.dartfiles; the correct file is resolved by searching all indexed results - Smart Navigation: Converts widget names to snake_case, resolves imports from
routes.gr.dart, mapspackage:…to file paths (supports nested structures), and opens the widget file - Conflict Detection: Automatically hides CodeLens when multiple widgets match the same route to prevent ambiguity
- Real-time Updates: Refreshes automatically when any
routes.gr.dartfile is saved - Zero Configuration: Works out of the box with standard AutoRoute setups
-
Discover AutoRoute configuration
- Scans
.dartfiles for@AutoRouterConfig(...)and extractsreplaceInRouteName, e.g.'Screen|Page,Route'. - Supports multiple source suffixes before the comma (e.g.,
Screen|Page|View) and a generated suffix after the comma (e.g.,Route). - From the annotation file name (e.g.,
app_router.dart), derives the paired generated file (e.g.,app_router.gr.dart).
- Scans
-
Index generated imports
- Reads imports from the paired
*.gr.dartfile. - Converts
package:foo/bar.dart→lib/bar.dartand verifies files exist locally.
- Reads imports from the paired
-
Detect route classes in editors
- Detects route tokens with the generated suffix (e.g.,
HomeRoute). - CodeLens only appears on route classes, not on widget classes (e.g.,
HomePage,HomeScreen). - Skips
AutoRouteitself.
- Detects route tokens with the generated suffix (e.g.,
-
Resolve targets
- For
HomeRoute, computes baseHomeand tries all source suffixes (e.g.,HomeScreen,HomePage) against imports from the paired*.gr.dartfile(s). - Conflict detection: If multiple widgets match (e.g., both
HomePageandHomeScreenexist), CodeLens is hidden to avoid ambiguity. - Shows CodeLens only when exactly one widget file is found and resolvable.
- For
-
Navigate
- Opens the resolved file and focuses the widget class.
If no generated route files are found, a notification is shown on activation.
- Flutter project using AutoRoute
- At least one generated route file (
.gr.dartextension) containing the// AutoRouterGeneratorcomment
- Install the extension
- Open a Dart file containing route references (e.g.,
CompaniesRoute()) - Look for the CodeLens button above the route class (e.g., "🔗 Jump to CompaniesScreen")
- Click the button to navigate to the corresponding widget file
// In your Dart file
context.router.push(const CompaniesRoute());
// The extension will:
// 1. Detect CompaniesRoute
// 2. Show "🔗 Jump to CompaniesScreen" button
// 3. When clicked, find this import in routes.gr.dart:
// import 'package:myapp/features/companies/screens/companies_screen.dart' as _i4;
// 4. Convert to: lib/features/companies/screens/companies_screen.dart
// 5. Open the file and focus on the CompaniesScreen classThe extension automatically handles various project structures by reading import paths from routes.gr.dart:
lib/
├── routes.gr.dart
├── features/
│ ├── companies/
│ │ └── screens/
│ │ └── companies_screen.dart
│ └── profile/
│ └── screens/
│ └── profile_detail_screen.dart
└── main.dart
- Ensure generated route files exist: The extension shows a notification if no
.gr.dartfiles with// AutoRouterGeneratorare found. - Verify AutoRoute generation: Make sure your routes are generated and imports exist for your widgets.
- Open the correct workspace root: Discovery runs from the VS Code workspace folder(s).
- Check import statements in your
routes.gr.dartfor the target widget (snake_case match). - Verify file naming: Widget files should be in snake_case (e.g.,
companies_screen.dart). - Confirm file exists at the path resolved from the import (
package:…→lib/…).
- The extension scans all discovered
.gr.dartfiles containing// AutoRouterGeneratorand uses the first matching import. - If you have multiple apps/packages, ensure imports are unambiguous.
- Multi-project workspaces: Project scoping is experimental. In multi-project/mono-repo setups, route resolution can cross project boundaries or miss matches. For now, opening a single project (one
pubspec.yaml) yields the most reliable results. - The extension will only work when widgets are in their own file, and widget names must be unique. If you have two widgets with the same name, the extension will hide CodeLens to avoid conflicts.
- CodeLens only appears on route classes (e.g.,
HomeRoute), not on widget classes (e.g.,HomePage,HomeScreen). This ensures navigation always goes from route → widget, following AutoRoute's generation pattern. Example:
// file name: home_screen.dart
@RoutePage()
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container();
}
}- Open Help > Toggle Developer Tools to view logs.
- Look for messages prefixed with "Auto Route Finder:" when resolving imports and opening files.
See CHANGELOG.md for detailed release notes.
Contributions are welcome! Please feel free to submit issues and pull requests.
MIT License - see LICENSE file for details.
