Getting Started
Build your first modular Flutter app in 3 steps.
1. Install
flutter pub add go_router_modular2. Setup App
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Modular.configure(
appModule: AppModule(),
initialRoute: '/',
debugLogDiagnostics: true,
debugLogDiagnosticsGoRouter: true,
debugLogEventBus: true,
);
runApp(AppWidget());
}
class AppWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ModularApp.router(
title: 'My App',
);
}
}
class AppModule extends Module {
@override
List<ModularRoute> get routes => [
ModuleRoute('/', module: HomeModule()),
];
}
class HomeModule extends Module {
@override
FutureBinds (Injector i) { // Opitional
i.addSingleton<HomeController>((i)=> HomeController());
}
@override
List<ModularRoute> get routes => [
ChildRoute('/', child: (context, state) => HomePage()),
];
}That's it! Your modular app is ready.
Next Steps
- Routes & Modules - Learn routing
- Dependency Injection - Master DI
- Page Transitions - Add animations