Router Builder
Define Flutter routes with @RT(), then use the generated Routes and
RoutesHelper classes to look up routes and match incoming deep links.
AI coding-assistant support (agent plugin)
This repository ships an installable agent plugin for Claude Code and
OpenAI Codex with package-specific skills: project setup, adding routes,
policy and deep-link debugging, generation troubleshooting, route audits, and
migrations from 2.x through 4.x. It extends your coding agent only - it
adds no code, dependency, or telemetry to your Flutter app, and it is
distributed from this repository (not inside the pub.dev package archive).
Install in Claude Code (CLI/desktop v2.x):
/plugin marketplace add omar-hanafy/router_builder
/plugin install router-builder@router-builder-plugins
Install in Codex (CLI 0.144+; plugins also work in ChatGPT desktop/web
Work mode, not the IDE extension):
codex plugin marketplace add omar-hanafy/router_builder
codex plugin add router-builder@router-builder-plugins
Start a new session after installing. Then just ask normally - "add an
orders screen at /orders/:orderId, deep-linkable, auth required", "why does
myapp://profile/9 open nothing?", "upgrade us from router_builder 2 to 3" - or
invoke a skill explicitly: /router-builder:add-route (Claude Code) /
$router-builder:add-route (Codex). Claude Code additionally gets a read-only
route-auditor subagent for full route audits.
The plugin includes the v2-to-v3 and v3-to-v4 migration scripts. Each previews
its edits by default. The copies bundled with the plugin match the scripts
under tool/. Installation and update instructions are in the
plugin guide.
Features
- 🚀 Code Generation: Automatically generates route helpers from annotations
- 🔗 Unified Deep Links: Routes and deep links defined in one place
- 🛡️ Type Safety: Strongly typed route definitions and navigation
- ⚡ Build-time Validation: Detects route conflicts during generation
- 🎯 Simple API: Clean, intuitive route definition syntax
- 🏷️ Localized Titles: Optional
title callback for per-route titles that react to locale changes
- 👮 Policy-Driven: One
RoutePolicy for all behavior, resolved Call -> Route -> Global
- 🗂️ Categorized Routes: Generated
RoutesHelper exposes normalRoutes, globalRoutes, popupRoutes, authorizedRoutes, redirectRoutes, branch maps, and a deepLinkMap
- 🩺 Diagnostics: JSON-safe
report() on RoutePolicy, RouteInfo, and RouteArgs
Upgrading from v2? See MIGRATION_GUIDE.md for the
full v2 -> v3 guide. Key changes: one RoutePolicy for all behavior, a single
import 'package:router_builder/router_builder.dart', and generated Routes /
RoutesHelper in routes.g.dart. The mechanical edits (removing isIdSlug,
MyRoutes -> Routes, import moves) are automated by tool/migrate_to_v3.sh
(dry-run by default; --write to apply).
Getting Started
Installation
For an app that generates routes, add the runtime and build tools to your
pubspec.yaml.
dependencies:
router_builder: ^4.0.0
dev_dependencies:
build_runner: ^2.15.0
router_builder_generator: ^4.0.0
router_builder provides the annotations, RouteInfo, route policies, and
deep-link matcher. An app that uses checked-in generated routes only needs
the runtime. Add the two dev dependencies when you want to regenerate those
routes. Pub resolves the generator's analyzer and build tools alongside that
app's other dependencies. Packages that use the runtime alone pass only its
runtime dependencies on to their consumers.
Upgrading from 3.x? Route annotations and models keep their imports.
Apps that regenerate routes add the generator to their dev dependencies.
For custom builders, update the build configuration and run
dart run router_builder_generator:migrate_builder_imports to preview Dart
directive changes. Apply them with --write before running general Dart
fixes so prefixed names keep their original bindings. Migration guide
Basic Usage
- Define your routes using the
@RT() annotation:
import 'package:router_builder/router_builder.dart';
import 'screens/home_screen.dart';
import 'screens/profile_screen.dart';
class AppRoutes {
@RT()
static final home = RouteInfo(
'home',
title: (context, [args]) => context.tr.homeTitle,
builder: (context, args) => HomeScreen(),
);
@RT()
static final profile = RouteInfo(
'profile',
path: 'profile/:id',
title: (context, [args]) => context.tr.profileTitle,
builder: (context, args) => ProfileScreen(userId: args?.id),
deepLinkNames: ['user'], // Alternative deep link: /user/:id
);
}
- Run the generator:
dart run build_runner build