GoRouter Modular

Modular architecture for Flutter apps. Build scalable applications with clean modules, built-in dependency injection, and powerful routing — all on top of go_router (opens in a new tab).
Install
flutter pub add go_router_modularMinimal Example
lib/main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Modular.configure(
appModule: AppModule(),
initialRoute: '/',
);
runApp(AppWidget());
}lib/src/app_widget.dart
class AppWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ModularApp.router(title: 'My App');
}
}lib/src/app_module.dart
class AppModule extends Module {
@override
List<ModularRoute> get routes => [
ModuleRoute('/', module: HomeModule()),
];
}lib/src/modules/home/home_module.dart
class HomeModule extends Module {
@override
FutureBinds binds(Injector i) {
i.addSingleton<HomeController>((i) => HomeController());
}
@override
List<ModularRoute> get routes => [
ChildRoute('/', child: (context, state) => HomePage()),
];
}Features
| Feature | Description |
|---|---|
| Modules | Encapsulate routes, dependencies, and logic into self-contained units |
| Dependency Injection | Singleton, factory, and lazy singleton registration with auto-dispose |
| Smart Routing | ChildRoute, ModuleRoute, ShellRoute, and StatefulShellRoute |
| Page Transitions | Built-in animations via go_transitions (opens in a new tab) |
| Event System | Decoupled cross-module communication |
| Shell Routes | Shared layouts with persistent tab state (IndexedStack) |
Next Steps
- Quick Start — Set up your first modular app
- Routes & Modules — Understand the routing system
- Dependency Injection — Manage dependencies
- Shell Routes — Build tab-based layouts
- Page Transitions — Add animations